CT052

Dutch Flag Sort

MediumAcceptance: 0.0%

Given an array of strictly the characters R, G, and B, segregate the values so all Rs come first, Gs second, and Bs last. You can only swap elements. Do this in linear time and in-place. Input: a string of R, G, B characters. Output: the sorted string.

Example 1:

Input: GBRRBRG
Output: RRRGGBB

Example 2:

Input: RGB
Output: RGB

Constraints:

1 <= len(string) <= 10^5 String contains only R, G, B

Tags:

sorting two-pointers array
Loading...
Test Cases:No test cases
No test cases available.