Please explain the logic behind the code
Doubt regarding ques sort 0,1,2
You have to solve this question using Dutch National Flag algorithm, maintain 3 pointers, mid, low and high, and based on that you have to solve it linear time. There is a hint video also, you can refer to that .