Closest Number Pairs
Reported by candidates from Adobe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Adobe OA from March 2026 looks like a freebie, and that's exactly where people slip. Closest Number Pairs asks for the minimum absolute difference in an array, then every pair that hits it. The trap is the brute force. With up to 10^5 values, checking all pairs times out fast. It's a sorting problem in disguise, and the answer lives in adjacent elements only. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and surfaces the approach so you can still finish clean.
The problem
Given an integer array numbers, find the minimum absolute difference between any two values. Return every pair that has this minimum difference as a two-dimensional integer array. Within each pair, place the smaller value first. Order the returned pairs by their first value in ascending order. Function closestNumberPairs(numbers: int[]) → int[][] Examples Example 1 numbers = [4,2,1,3] return = [[1,2],[2,3],[3,4]] After sorting, the array is [1,2,3,4]. Every adjacent difference is 1, so all three adjacent pairs are returned. Example 2 numbers = [-10,-3,0,5] return = [[-3,0]] The sorted adjacent differences are 7, 3, and 5. Only [-3,0] has the minimum difference. Constraints 2 <= numbers.length <= 10^5. -10^9 <= numbers[i] <= 10^9. All values in numbers are distinct.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort the array. The minimum difference between any two values must occur between neighbors in sorted order, because anything wider has a neighbor sitting in between with a smaller gap. One pass computes adjacent differences and tracks the minimum. A second pass, or a reset-on-new-minimum trick in the same pass, collects every pair matching it. Sorting keeps pairs ordered by first value automatically, and the smaller value comes first for free. The pitfalls are real. Differences can reach 2*10^9, which overflows a 32-bit int, so use a long. Don't clear your result list incorrectly when a smaller minimum appears. Values are distinct, so you never get a zero difference. Complexity is O(n log n) time. If the clock is ticking and your brain stalls, StealthCoder is the safety net that shows the sort-then-scan solution during the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Closest Number Pairs cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimum absolute difference. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Adobe's OA.
Adobe reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Closest Number Pairs FAQ
What's the trick in Closest Number Pairs?+
Sort first. The smallest gap between any two numbers always shows up between adjacent elements in sorted order. So you never compare all pairs. One scan over neighbors finds the minimum, and the same scan or a second one collects every pair that matches it.
Can I solve it without sorting?+
Not usefully. Without sorting you're back to O(n^2) pair checks, which dies at 10^5 elements. Sorting at O(n log n) is the intended path. A radix or bucket approach exists but adds complexity for no real gain here.
What edge cases break a naive solution?+
Integer overflow is the big one. Values go from -10^9 to 10^9, so a difference can hit 2*10^9, past a 32-bit int. Also watch resetting your result list when you find a new smaller minimum, and the two-element array case where you return one pair.
How do I keep the output ordered correctly?+
Sorting ascending handles both rules. Each adjacent pair is already smaller-first, and pairs come out in ascending order of their first value as you scan left to right. No extra sort of the result is needed.
How do I prep for this in 48 hours?+
Write it once from scratch: sort, find the min gap, collect pairs. Then test with negatives, two elements, and extreme values like -10^9 and 10^9. It takes under 15 minutes. Spend the rest of your time on other sorting and array scan patterns Adobe might throw at you.