Amazon interview question

The second question was a string implementation problem,