Sort colors Dutch flag
Your task
Given an array nums containing only the integers 0, 1, and 2 representing colors, sort it in place so all 0s come first, then 1s, then 2s, using a SINGLE pass and O(1) extra space (the Dutch National Flag partition). Do not use the library sort or counting into a second array. Return the sorted array. Length up to 3*10^4.
Examples
sort_colors(nums: list[int]) -> list[int]Example 1
Input
sort_colors([2, 0, 2, 1, 1, 0])Output
[0, 0, 1, 1, 2, 2]