Amazon interview question

Just ask me to solve the coding problem