Amazon interview question

Data structures and algorithms problem