Amazon interview question

2 leetcode style problems on hackerank