TikTok interview question

An data structure problem in leet code