Scramble String

Write a method that takes in a string and an array of indices in the string. Produce a new string, which contains letters from the input string in the order specified by the indices of the array of indices.

Screen Shot 2016-08-19 at 3.07.43 PM

Note the lack of ‘if’ statement and how idx is incremented inside the while loop.

Second time solving this:

It helps to write out the new string positions beforehand.


Third time doing this, I got a bit too creative but it worked:


Scramble String

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s