DSA · Reimagined
Arrays medium time O(n) space O(1)

Dutch National Flag

With values limited to 0, 1 and 2, keep settled 0s on the left and settled 2s on the right, sorting the middle. One pass with low/mid/high pointers places every value.

2
0
0
1
2
2
1
3
1
4
0
5
1
6
2
7
0
8

Values are only 0, 1 or 2. Three pointers: low, mid, high.

1 / 11

Practice

Machine twin: /dsa-viz-v2/dutch-national-flag.json — the full deterministic run as structured data.