Amazon interview question

Algorithm related