Amazon interview question

medium difficulty of leetcode problems