Amazon Interview Question

A easy and medium leetcode question