Amazon interview question

Standard CS coding question