Amazon Interview Question

2 medium questions at leetcode