Amazon interview question

the string related question on java was the toughest...