Amazon interview question

Problems from leetcode in general