TikTok interview question

2 Leetcode Medium to Hard problems.