Challenge: Dutch National Flag Problem
Let's solve the famous problem of Dutch National Flag.
We'll cover the following
Problem statement
Implement a function that sorts a list of , and . This is called the Dutch National Flag Problem. Since the number can be represented by the blue color, by the white color, and as the red color, the task is to transform the list input to the Dutch flag.
Try solving this problem
in-place
and in linear time without using any extra space.
Input
An array of , , and
Output
An array where the numbers , , and are sorted
Sample input
lst = [2, 0, 0, 1, 2, 1, 0]
Sample output
result = [0, 0, 0, 1, 1, 2, 2]
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.