Amazon interview question

about optimization the code they need optimal one