Amazon Interview Question

2 hard leetcode questions in any language