Google interview question

Two leetcode medium questions, each roughly 40 mins