TikTok interview question

Medium to hard Data structures