Domanda di colloquio di ByteDance

What is the best data structure to solve this problem?