Back to problems

Sort Colors

Algorithm · Okx · Medium

Sort Colors You are given an array nums of length n whose entries are limited to 0, 1, and 2. Rearrange the array in place so that identical values are grouped together, with the groups ordered as 0, then 1, then 2. Library-provided sorting routines are not allowed. Your approach should make just one pass through the array if possible. Example 1 The values are reordered into ascending color groups while preserving the required in-place result. Example 2 Each of the three…

Checking your access…