arrays
sorting
two-pointers

Given an array nums containing only 0, 1, and 2, reorder it in-place so equal values are grouped together in the order red, white, blue. Return the final array after the in-place updates.

Examples

Example 1

Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]

Example 2

Input: nums = [2,0,1]
Output: [0,1,2]

Example 3

Input: nums = [0]
Output: [0]
🔒 6 hidden

Running will execute all 9 cases, including 6 hidden ones.