Amazon Interview Question

Leetcode easy type problem