Amazon Interview Question

Coding question on the hackerank