Amazon interview question

Leetcode style questions that were variations