Amazon interview question

almost average difficult, no too difficult one