Amazon interview question

Leetcode easy medium and hard