About the logic of the code

What is basically the logic behind this code implementation I mean why are we doing it or how and when to think of it?

pls can my doubt be cleared?It has been a week

hello @Senjuti256
we r segregating 0 , 1 ,2 using two pointer.
we r putting all 0 before 1 st pointer pointer.

and putting all 2’s after 2nd pointer.
in between those two pointer we r putting 1.

do a lot of problems on two pointers apporach , u will get the idea when to use it and when not.

where to get 2 pointer approach problems

check leet code… . . .