Amazon Interview Question

Programming Puzzle