Amazon interview question

Nothing too difficult although one should be strong with using data structures.