Amazon Interview Question

Fix some bugs in the code to make it work.