Luciq interview question

2 medium problems from leetcode