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 18 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.
- #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.