
Sort 0s, 1s, and 2s
via Dev.to PythonSaranya R
Approach Explanation (o゜▽゜)o☆ I used three pointers: low=0, mid=0, and high=len(arr)-1. I placed 0's at the beginning by swapping with low. I left 1's in the middle. I placed 2's at the end by swapping with high. I repeated until mid-crossed high, and the array was sorted. Methods Used ( ノ ^-^)ノ Dutch National Flag algorithm (single pass) Three-pointer technique (low, mid, high) Constant space (no extra array used)
Continue reading on Dev.to Python
Opens in a new tab
0 views


