FrontendX
Sort Colors (Dutch Flag)
medium
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Sort Colors
(Dutch Flag)
Sort array containing 0s
Examples
Example 1
Input:
[1,2,3]
Output:
[1,3,2]
Example 2
Input:
[1,2,3]
Output:
[1,3,2]
Hints
Hint 1
Use three pointers: low, mid, high.
Hint 2
Dutch national flag algorithm partitions in one pass.
Hint 3
0s before low, 1s between low and mid, 2s after high.
Sort Colors (Dutch Flag)
Sort array containing 0s