Amazon interview question

Tries and back tracking question