Amazon interview question

solve frequently used string problem