CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsArrays

Sort Colors

Medium
LeetCode
12/14
MediumArraysLeetCode #75

Sort Colors (Dutch National Flag)

Array of 0,1,2 only. One-pass three pointers: lo, mid, hi.

Examples

Example 1

Input

6
2 0 2 1 1 0

Output

0 0 1 1 2 2
Example 2

Input

3
2 0 1

Output

0 1 2

Stuck? Take a nudge

C++17Autosaves