Amazon interview question

Leetcode style coding questions as usual