TikTok Interview Question

leetcode mid problem, data structure