Amazon interview question

Data structure question