TikTok interview question

A Leetcode Medium Design problem