Amazon interview question

some debug and algorithms