Amazon Interview Question

Asked to write pseudo code on a whiteboard.