We can have 3 pointers: low, mid and high. low and high are at the either ends of the array and mid traverses through it. If element at mid == 0, we swap it with low pointer, if element at mid == 1, we simply move forward else it is 2 for which we swap it with high pointer. The loop runs till mid≤high.


