Sort Colors
Try to solve the Sort Colors problem.
We'll cover the following
Statement
Given an array, colors
, which contains a combination of the following three elements:
-
(representing red)
-
(representing white)
-
(representing blue)
Sort the array in place so that the elements of the same color are adjacent, with the colors in the order of red, white, and blue. To improve your problem-solving skills, do not utilize the built-in sort function.
Constraints:
-
colors.length
300 colors[i]
can only contain s, s, or s.
Examples
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy