Amazon interview question

Coding questions from leetcode and hackerank.