Amazon interview question

Coding question on the hackerank