Amazon interview question

Asked to write pseudo code on a whiteboard.