Amazon Interview Question

Fix the code here to properly implement the algorithm.