Challenge: Dutch National Flag Problem
Let's solve the very famous problem of Dutch national flag.
We'll cover the following
Problem statement
Implement a function that sorts an array of , and . This is called the Dutch national flag problem. Since the number can be represented as the blue color, as the white color, and as the red color, we want the array to form the Dutch flag.
Try solving this problem
inplace
and in linear time without using any extra space!
Input
The input is an array of , and
Output
The output is a printed array where the numbers , , and are sorted
Sample input
arr = {2, 0, 0, 1, 2, 1, 0}
Sample output
0 0 0 1 1 2 2
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.