Amazon Interview Question

Just a standard LeetCode question.