Reported September 2026
Capital Onesorting

Sort Adjacent Pairs

Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capital One OA. Under 2s to a working solution.
Founder's read

Capital One reported this one in September 2026, and the input size is the first thing to check: up to 10^5 values, each from -10^9 to 10^9. That rules out anything quadratic and tempts you to sort the whole array, which is wrong. This is Sort Adjacent Pairs, tagged sorting, but the real task is a single linear pass that swaps two neighbors when they're out of order. If you've got an OA invite for Capital One, expect a short problem that punishes overthinking. StealthCoder is there as a safety net if you blank during the live assessment, but you probably won't need it.

The problem

Given an integer array values, independently sort each adjacent pair in nondecreasing order: indices 0 and 1 form the first pair, indices 2 and 3 form the second pair, and so on.
If the array has odd length, leave its final unpaired value unchanged. Return the resulting array without modifying the input array.

Function
sortAdjacentPairs(values: int[]) → int[]

Examples
Example 1
values = [5,4,2,3,7]
return = [4,5,2,3,7]
The pair [5,4] becomes [4,5], [2,3] is already sorted, and the final 7 is unpaired.
Example 2
values = [3,1,4,2]
return = [1,3,2,4]
Sort the two independent pairs [3,1] and [4,2].

Constraints
1 <= values.length <= 10^5
-10^9 <= values[i] <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that each pair is independent, so there's nothing to sort globally. Copy the array, then loop i from 0 in steps of 2 while i+1 is within bounds. If copy[i] > copy[i+1], swap them. That's O(n) time and O(n) space for the copy. If the length is odd, the loop stops before the last index, so the unpaired value stays put automatically. The common pitfalls are sorting the entire array, stepping by 1 instead of 2, running off the end on odd lengths, and mutating the input when the problem says not to. Values reach 10^9 in magnitude, which fits a 32-bit signed int, and you only compare them, so there's no overflow risk. If your mind goes blank mid-assessment, StealthCoder can supply this loop in seconds from the problem on screen, but the logic is short enough to hold in your head.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Sort Adjacent 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 StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Capital One's OA.

Capital One 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.

Sort Adjacent Pairs FAQ

How hard is Sort Adjacent Pairs really?+

It's easy. There's no tricky algorithm, just a stride-2 loop with a compare and swap. The difficulty is carelessness: off-by-one errors on odd-length arrays and accidentally modifying the input. If you read the statement once carefully, you'll finish in a few minutes.

What's the trick to this Capital One problem?+

Don't sort the whole array. Each pair is independent, so walk indices 0, 2, 4 and swap the two elements if the left one is larger. The odd leftover element never gets touched, so it stays unchanged without special handling.

Do I need to worry about the 10^5 input size?+

Yes, a little. It rules out quadratic approaches, but a single O(n) pass is far under any reasonable limit. Even sorting each pair with a built-in sort works, though a simple compare and swap is cleaner and faster.

Can I modify the input array in place?+

No. The statement says to return the result without modifying the input. Make a copy first, using a slice or a copy constructor, then swap inside the copy and return it. Forgetting this is the most likely way to fail hidden tests.

How do I prepare for this in 48 hours?+

Write it once in your language of choice and test three cases: an even length, an odd length, and a single element. Then check pairs that are already sorted and pairs with equal values. That covers the edge cases, and the rest of your time is better spent on other array and sorting problems.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capital One.

OA at Capital One?
Invisible during screen share
Get it