Question d’entretien chez ByteDance

What is the best data structure to solve this problem?