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.
Showing 20 problems of 27
- #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.
- #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.