Stable Odd-First Partition
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reported this one in August 2020, and the detail that trips people is the negative number rule: -3 is odd, so you can't lean on a naive check that misses it. The task is a stable partition. Odds first, evens after, original order kept inside each group. It's tagged dynamic-programming in the source, but nothing here needs a DP table. If your OA invite lists this, expect a short, clean problem where speed and care matter more than cleverness. StealthCoder sits invisibly on your screen as a safety net if you blank on the live OA, but this one is easy to hold in your head.
The problem
Return a new array containing every odd value from nums first, followed by every even value. Preserve the relative order within both groups. Negative integers use ordinary divisibility by 2; for example -3 is odd. Function stableOddFirst(nums: int[]) → int[] Examples Example 1 nums = [2,3,4,1,6,5] return = [3,1,5,2,4,6] Both the odd and even subsequences retain their input order. Constraints 0 <= nums.length <= 10^5.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that it's not really dynamic programming. It's a single pass with two buckets. Walk nums once, push odd values into one list and even values into another, then concatenate. That's O(n) time and O(n) space, and the stability comes for free because you append in input order. The pitfall is the negative check. In many languages, x % 2 == 1 fails for -3 because the remainder is -1. Use x % 2 != 0 or (x & 1) instead. Another trap is trying an in-place swap partition, which breaks stability and fails the example [2,3,4,1,6,5]. Also handle the empty array, since nums.length can be 0. With n up to 10^5, the two-list approach is plenty fast. If you freeze mid-assessment, StealthCoder is the hedge that hands you this exact solution while you recover.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Stable Odd-First Partition 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Stable Odd-First Partition FAQ
How hard is the Stable Odd-First Partition problem really?+
Easy. It's a single pass with two lists. The only real risk is the negative-number parity check and forgetting the empty input. If you can write a loop and concatenate arrays, you can finish this quickly.
What's the trick to keeping order stable?+
Don't swap in place. Append each odd to one list and each even to another as you scan left to right, then join odds followed by evens. Appending in scan order preserves relative order inside both groups automatically.
Why does -3 cause bugs here?+
In many languages, -3 % 2 returns -1, not 1. So a check like x % 2 == 1 misclassifies negatives as even. Use x % 2 != 0 or x & 1 to detect odd values correctly for negative integers.
Do I need dynamic programming for this Bloomberg question?+
No. Despite the dynamic-programming hint, there's no overlapping subproblem. It's a stable partition solved with a linear scan. Reaching for a DP table just wastes time and adds bugs.
How do I prepare for this in 48 hours?+
Write the two-list solution once from memory, then test it on [2,3,4,1,6,5], an all-negative array, and an empty array. Also write the in-place stable variant only if you have spare time. The simple version passes the constraints.