Amazon interview question

solve meedium leetcode problem to solve