Amazon interview question

Whiteboard problem solving