TikTok interview question

leetcode 1863 and leetcode 76.