Amazon interview question

two coding questions of difficulty level leetcode medium