J.P. Morgan interview question

Very basic string manipulation questions