Amazon interview question

Collections related question