TikTok Interview Question

An data structure problem in leet code