NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

Advertisers run marketing campaigns that target users in specific geographic regions. These regions form a fixed hierarchy. For example:

  • "World" contains "Europe" and "US".
  • "Europe" contains "France" and "Germany".
  • "France" contains "Paris" and "Nice" and so on.

When an advertiser is granted access to a region, they automatically gain permission to all of its subregions. Likewise, revoking access to a region removes permission for that region and every subregion beneath it. You are asked to design a system that efficiently performs these grant and revoke operations for any advertiser and any region in the hierarchy.

Test Cases
Input
Output
Expected