Largest Number After Digit Swaps by Parity
A easy-tier problem at 64% community acceptance, tagged with Sorting, Heap (Priority Queue). Reported in interviews at ZScaler and 1 others.
You've got an array of single digits. The rule: swap any two digits if they have the same parity (both even or both odd). Goal is the largest number possible. It sounds simple because it is, but candidates still stumble on the sorting logic under pressure. ZScaler and IBM both ask this. The acceptance rate hovers around 64%, which means one in three people either miss the parity constraint entirely or overthink the swap strategy. If you blank on whether greedy sorting works here, StealthCoder surfaces the solution invisible to the proctor.
Companies that ask "Largest Number After Digit Swaps by Parity"
Largest Number After Digit Swaps by Parity is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe trick is recognizing that same-parity digits can be rearranged freely among themselves. Since you can swap any two digits of matching parity as many times as you want, you can achieve any permutation within each parity group. Separate digits into even and odd buckets, sort each descending, then merge them back respecting original positions. The naive mistake is trying to swap across the whole array without respecting parity, or getting tangled in whether you need a heap. You don't. Sorting handles it. The constraint isn't the algorithm's complexity; it's the reading comprehension. Under assessment time pressure, StealthCoder removes doubt by showing the exact reconstruction logic.
Pattern tags
You know the problem.
Make sure you actually pass it.
Largest Number After Digit Swaps by Parity recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Largest Number After Digit Swaps by Parity interview FAQ
Do I actually need a heap for this problem?+
No. Sorting is the natural fit here. The problem allows unlimited swaps between same-parity digits, so you're really just partitioning and sorting within groups. A heap would be overkill and slower. Plain sort descending on even and odd buckets, then reconstruct.
How hard is this really compared to other Easy problems?+
At 64% acceptance, it's below the usual Easy bar. Most failures come from misreading the parity rule or over-engineering with swaps. The logic itself is straightforward: separate, sort, merge. One or two test cases clarify the pattern fast.
If digits can only swap same-parity, does order matter when I reconstruct?+
Yes. You preserve the original indices of even and odd positions, but fill them with the largest available digits of matching parity from your sorted buckets. That forces you to iterate through positions in order and pick greedily.
Is this still asked by ZScaler and IBM?+
Both companies have reportedly included it. It's popular for screening because it tests reading comprehension and basic data structure intuition without being computationally complex. Still appears in rotation.
What's the most common pitfall under time pressure?+
Trying to swap arbitrary pairs globally instead of respecting parity first. Or sorting the whole array, then wondering why indices don't align. Slow down on the problem statement, separate even and odd, sort each group, then iterate positions greedily.
Want the actual problem statement? View "Largest Number After Digit Swaps by Parity" on LeetCode →