Shopee interview question

Data structure medium level as found on leetcode