Skip to content

Files

Latest commit

e9094bd · May 29, 2019

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 29, 2019
May 29, 2019

Given an array of strictly the characters 'R', 'G', and 'B', segregate the values of the array so that all the Rs come first, the Gs come second, and the Bs come last. You can only swap elements of the array.

Do this in linear time and in-place.

For example, given the array ['G', 'B', 'R', 'R', 'B', 'R', 'G'], it should become ['R', 'R', 'R', 'G', 'G', 'B', 'B'].