Amazon Interview Question

easy-medium leetcode question with help oft he interviewer