Amazon interview question

What data structure to use to solve the problem.