Amazon interview question

Hard lit code questions from Hacker Rank.