Amazon | Virtual Onsite | Rearrange letters in an array
Anonymous User
1644

Given an array only containing the letters 'C', 'R' and 'S', rearrange the letters in the array such that all 'C's are at the front and all 'S's are at the end of the array.

Example
Given array: ['R', 'C', 'C', 'S', 'R', 'R', 'S', 'C', 'S', 'R']

The output should be: ['C', 'C', 'C', 'R', 'R', 'R', 'R', 'S', 'S']

EDIT: I forgot to mention, but the challenge here was to do it in one pass. That is using just one for loop.

Comments (9)