Skip to main content

Square Coding Interview Questions

27 Square coding interview problems with full optimal solutions — 18 easy, 7 medium, 2 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Square interviewer values, and a FAQ section.

  • #15easyfoundational

    15. Two Sum II - Input Array Is Sorted

    Given a sorted list of settled transaction amounts, find two that match a target refund — Square's refund-matching engine does exactly this to pair a chargeback against two split payments without rescanning the ledger.

  • #16easyfoundational

    16. Valid Anagram

    Determine whether two merchant category codes are permutations of each other — Square's risk team uses character-frequency checks to detect look-alike merchant names that attempt to spoof category routing.

  • #17easyfoundational

    17. First Bad Version

    Find the first firmware release that broke POS terminal compatibility — Square ships hundreds of hardware versions and uses binary search to pinpoint the exact SDK version that introduced a payment-flow regression without re-running every build.

  • #18easyfoundational

    18. Move Zeroes

    Push zero-amount line items to the end of a POS receipt array while keeping non-zero charges in order — Square's receipt-rendering pipeline compacts voided items in-place before printing, without allocating a second buffer.

  • #19mediumfoundational

    19. 3Sum

    Find every trio of transaction adjustments in a ledger that net to zero — Square's reconciliation engine flags three-way payment splits that cancel out, which can signal money-laundering patterns in its fraud-detection pipeline.

  • #20mediumfoundational

    20. Group Anagrams

    Cluster merchant names that are anagrams of each other so Square's compliance team can batch-review aliases — a hash-map keyed on sorted character signatures groups thousands of merchant strings in a single linear pass.

  • #21mediumfoundational

    21. Coin Change

    Find the minimum number of denominations to make exact change at a Square POS register — this DP problem mirrors the coin-selection logic that Square's hardware team optimizes for cash-drawer accuracy across hundreds of currency configurations.

  • #22mediumfoundational

    22. Meeting Rooms II

    Find how many Square Appointments booking slots overlap simultaneously — Square's scheduling infrastructure uses this interval-heap pattern to compute the minimum number of POS terminals needed to handle concurrent appointment peaks without double-booking.

  • #23mediumfoundational

    23. Top K Frequent Elements

    Surface the K most common payment failure codes from a transaction log — Square's Payments Risk team runs this query at dashboard refresh time to triage which error categories need immediate incident response.

  • #24mediumfoundational

    24. Product of Array Except Self

    Compute each payment terminal's contribution factor without dividing out that terminal's own volume — Square's analytics team uses a no-division prefix-product scan to generate per-merchant weight arrays for settlement-fee allocation without floating-point precision loss.

  • #25mediumfoundational

    25. Longest Consecutive Sequence

    Find the longest unbroken streak of daily transaction IDs in a batch — Square's reconciliation team uses this hash-set scan to detect gaps in sequential invoice numbering that indicate missing or voided payments without sorting the full ledger.

  • #26hardfoundational

    26. Median of Two Sorted Arrays

    Find the median settlement time across two independently sorted streams of payment batches — Square's treasury team computes this real-time percentile across bank ACH and card-network queues to hit SLA commitments without merging two large sorted logs.

  • #27hardfoundational

    27. Trapping Rain Water

    Calculate the maximum funds that can accumulate between settlement barriers in a payout timeline — Square's Banking team models daily balance troughs between large outflows exactly this way: water trapped between elevation bars mirrors cash trapped between sequential large disbursements.

  • #1easyfrequently asked

    1. Two Sum

    Given an array of integers and a target, return indices of two numbers that add up to the target. Square asks this as a warm-up to gauge whether you reach for hash maps the moment lookup-by-value enters the picture — a habit that scales into their transaction-matching code.

  • #2easyfrequently asked

    2. Valid Parentheses

    Given a string of brackets, decide whether it is well-formed. Square uses this to check whether you reach for a stack the instant 'matching' enters the picture — the same instinct they want when reconciling open transactions against captures.

  • #3easyfrequently asked

    3. Merge Two Sorted Lists

    Splice two sorted linked lists into one sorted list. Square uses this to test pointer-discipline — the same care needed when reconciling two ordered streams of transaction events for offline-first sync.

  • #4easyfrequently asked

    4. Best Time to Buy and Sell Stock

    Find the max profit from one buy and one sell over a price array. Square uses this to test whether you spot the single-pass running-minimum pattern — the same trick they apply to compute peak-vs-trough deltas on Cash App balance histories.

  • #5easyfrequently asked

    5. Contains Duplicate

    Given an array, return whether any value appears at least twice. Square uses this trivial-seeming problem as a habit check — they want the Set reach, not a nested loop, because their idempotency-key pipelines depend on the same instinct.

  • #6easyfrequently asked

    6. Maximum Subarray

    Find the contiguous subarray with the largest sum. Square tests Kadane's algorithm because the same running-state pattern shows up in their net-flow reconciliation jobs where you want the best contiguous window of debits vs credits.

  • #7easysometimes asked

    7. Climbing Stairs

    Count the distinct ways to climb n stairs taking 1 or 2 steps. Square uses this as a DP primer to see whether you spot the Fibonacci recurrence — and whether you reach for memo or iteration, signalling how you'd handle state machines in their transaction-retry logic.

  • #8easysometimes asked

    8. Single Number

    Find the element that appears once when every other element appears twice. Square uses this to test whether you spot the XOR trick — the same bitwise reasoning their payment-checksum and tamper-detect routines rely on.

  • #9easysometimes asked

    9. Linked List Cycle

    Detect whether a linked list contains a cycle. Square tests Floyd's tortoise-and-hare to gauge pointer dexterity and constant-space thinking — the same care needed when traversing offline transaction journals that may have malformed forward refs.

  • #10easyfrequently asked

    10. Reverse Linked List

    Reverse a singly linked list. Square uses this to test that you can manipulate next-pointers without losing nodes — the same discipline they expect when replaying out-of-order event logs during offline-to-online POS sync.

  • #11easysometimes asked

    11. Invert Binary Tree

    Invert (mirror) a binary tree by swapping every node's left and right child. Square asks this to test whether you can write clean recursive tree code — the same readability they expect in their state-machine traversal code for transaction lifecycles.

  • #12easysometimes asked

    12. Maximum Depth of Binary Tree

    Return the maximum depth of a binary tree. Square uses this as a warm-up to see whether you can write a clean post-order recursion before tackling harder tree problems like balance and path-sum.

  • #13easysometimes asked

    13. Same Tree

    Check whether two binary trees are structurally identical and have equal values. Square uses this to validate that you can write symmetric recursion — same instinct they want when comparing two replicas of an inventory tree during offline sync conflict resolution.

  • #14easysometimes asked

    14. Symmetric Tree

    Determine whether a tree is a mirror image of itself. Square uses this as a sibling problem to Same Tree to see if you can adapt the recursion shape — the kind of pattern transfer they want when porting logic between desktop and mobile POS clients.

Square Coding Interview Questions — Full Solutions — InterviewChamp.AI