Given an array containing only the values 0, 1 and 2, sort it in place in a single pass without using a separate counting or sorting step.
Example 1
Explanation: All 0s move to the front, all 2s move to the back, and the 1s settle in between — in one pass.
Example 2
Explanation: An already-sorted input is left untouched.
Example 3
Explanation: A single repeated color needs no swaps at all.
How would you generalize this one-pass partition to k distinct integer values instead of exactly 3?
Code execution is coming soon.