Solution Review: Partitioning of 0s and 1s
Let's look at the solution to the challenge posed in the previous lesson.
We'll cover the following
Solution
We begin at both ends. The left end stores the start index and the right end stores the last index. We traverse from the left till we have 0s in the array. Then we traverse from the right till we have 1s in the end. Finally, we swap the two and follow the same process till the left is less than the right.
Letās look at an illustration of the algorithm above.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.