Amazon Interview Math Problem