Sort Colors
Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the colors and the Capital One problem reported in October 2026 is just three buckets and one pass. Sort Colors hands you an array of 0s, 1s, and 2s and says rearrange it in place, no library sort. If your OA invite lands in the next few days, this is the kind of question that looks easy and punishes sloppy pointer work. The pattern is two pointers with a partition, the Dutch national flag idea. You can solve it in one pass with constant space. If your mind goes blank mid-assessment, StealthCoder runs invisibly as a safety net and gives you the solution live.
The problem
You are given an integer array nums containing only 0, 1, and 2. Rearrange the array in place so that equal values are adjacent and the values appear in the order 0, 1, then 2. Do not call a library sorting routine. Return the same array after rearranging it so the result can be evaluated. Function sortColors(nums: int[]) → int[] Examples Example 1 nums = [2,0,2,1,1,0] return = [0,0,1,1,2,2] The two zeros come first, followed by the two ones and the two twos. Example 2 nums = [2,0,1] return = [0,1,2] Each color occurs once. Constraints 1 <= nums.length <= 100000 nums[i] is 0, 1, or 2. The rearrangement must use constant auxiliary space.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a three-way partition. Keep low, mid, and high pointers. Low marks where the next 0 goes, high marks where the next 2 goes, and mid scans. If nums[mid] is 0, swap with low, then advance both low and mid. If it's 1, just advance mid. If it's 2, swap with high and shrink high, but do NOT advance mid, because the swapped-in value is unchecked. That last detail is the classic pitfall. People advance mid after a 2-swap and leave a stray 2 or 0 behind. The alternative is a counting pass followed by an overwrite pass. It's two passes and still O(1) space, and it's valid, but the one-pass version is what interviewers expect. Time is O(n), space is O(1). If you freeze during the live OA, StealthCoder is the hedge that hands you the pointer logic while you type.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Sort Colors 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as sort colors. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Capital One's OA.
Capital One reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sort Colors FAQ
How hard is Sort Colors really?+
It's a medium on paper but easy once you know the partition idea. The logic is about ten lines. The difficulty is handling the pointer moves correctly, especially not advancing mid after swapping with high. Trace the two examples by hand once and you're set.
What's the trick for the Capital One version?+
Use three pointers: low, mid, high. Send 0s to the front, 2s to the back, and let 1s fall in the middle. Swap, don't shift. This gives one pass, O(n) time, and O(1) extra space, which matches the constant auxiliary space constraint.
Can I just count the zeros, ones, and twos?+
Yes. Count each value, then overwrite the array with that many 0s, 1s, and 2s. It's two passes, O(n) time, O(1) space, and it meets the constraints. It's a safe fallback if you can't recall the three-pointer version under pressure.
Why does mid not advance after swapping with high?+
The value you swapped in from the high end hasn't been inspected yet. It could be a 0, 1, or 2. If you move mid forward, you skip it and can leave the array unsorted. After a swap with low, the swapped value is always a 1, so advancing is safe.
How do I prepare for this in 48 hours?+
Write the three-pointer solution from memory twice. Then test edge cases: a single element, all identical values, and an already sorted array. Also practice explaining why it's O(n) and O(1). That covers what a Capital One style OA would check.