Luciq Interview Question

2 medium problems from leetcode