An array contains only the integers `0`, `1`, and `2`. Implement `sortColors(nums)` that sorts it in a single pass and returns the sorted array. (This is the Dutch national flag problem.)
+ 2 hidden tests run on Submit.
Three pointers partition the array into 0s, 1s, and 2s in one pass. A 0 is swapped to the low region, a 2 is swapped to the high region, and a 1 stays in place. O(n) time, O(1) space — faster than a comparison sort because the value range is fixed.
Run your code to see results.