← Visualizers
Partitioning & Window LeetCode 75

Sort Colors / visualized

Sort an array of 0s, 1s, and 2s in one pass, in place — Dijkstra's Dutch National Flag partition. Three regions grow as mid scans: 0s to the left, 2s to the right, everything unclassified in the middle.

Execution

idle
[0, low) → 0s [low, mid) → 1s [mid, high] → unknown (high, end] → 2s
Press Run to begin.
0 / 0
Speed

Java · running line

0 (red) 1 (white) 2 (blue)
O(n) time · O(1) space  ·  mid only advances after a 0 or 1 swap — after swapping in a 2, the new value at mid is unexamined, so it stays put.