Amazon Interview Question

LeetCode question hard and easy