Sunday, March 23, 2014

String Reorder Distance Apart

Q:
Given a string of lowercase characters, reorder them such that the same characters are at least distance d from each other.
Input: { a, b, b }, distance = 2
Output: { b, a, b }
A:
   

sort the characters and build the new string from them.

each time, we extract the d chars and add them at the tail of output.

No comments:

Post a Comment