Amazon Interview Question

The second question was a string implementation problem,