Sort Colors (Dutch Flag Problem)

Medium

📝 Description

Sort an array of 0s, 1s, and 2s in-place using the Dutch National Flag algorithm.

Input Format

[0, 1, 2, 0, 1, 2] (array of 0s, 1s, and 2s)

Output Format

[sorted array]

Constraints

1 ≤ n ≤ 300

🔍 Sample Input

[2,0,2,1,1,0]
            

✅ Sample Output

[0,0,1,1,2,2]
            

Code Editor

Please login to run and submit code.

Shortcuts: Ctrl+Enter to submit, Ctrl+Shift+R to run