TikTok interview question

leetcode mid problem, data structure