Amazon Interview Question

2 leetcode style problems on hackerank