Subtree Access Overrides
Updated
Problem statement
A service has n regions numbered from 0 to n - 1. The array parent describes one rooted tree: parent[0] = -1, and for every other region v, parent[v] is its parent.
Every region initially has no access. Process the operations in order. operations[i] is paired with regions[i]:
GRANTgrants access to the named region and every region in its subtree.DENYdenies access to the named region and every region in its subtree.CHECKrecords whether the named region currently has access.
A later grant or denial overrides every earlier operation that applies to the same region. Equivalently, a check uses the most recent grant or denial issued at the queried region or any of its ancestors. If none exists, the result is false.
Return the boolean results of all CHECK operations in encounter order.
Function
resolveRegionAccess(parent: int[], operations: String[], regions: int[]) → boolean[]Examples
Example 1
parent = [-1,0,0,1,1,2]operations = ["CHECK","GRANT","CHECK","CHECK","DENY","CHECK","CHECK"]regions = [3,0,4,5,1,3,5]return = [false,true,true,false,true]The grant at the root reaches every region. The later denial at region 1 removes access only from that subtree, so region 3 is denied while region 5 remains granted.
Example 2
parent = [-1,0,0,1,1]operations = ["GRANT","DENY","CHECK","GRANT","CHECK","CHECK"]regions = [0,1,3,3,3,4]return = [false,true,false]The denial at region 1 overrides the root grant for its subtree. Granting region 3 later restores access only there; its sibling region 4 stays denied.
Example 3
parent = [-1,0,1,2]operations = ["GRANT","DENY","CHECK","GRANT","CHECK","CHECK"]regions = [0,2,3,0,3,2]return = [false,true,true]The denial at region 2 first overrides the earlier root grant for regions 2 and 3. The later root grant then becomes the newest applicable operation for the entire tree.
Constraints
1 <= parent.length <= 200000.parent[0] = -1, andparentdescribes one valid tree rooted at region0.1 <= operations.length = regions.length <= 200000.- Every operation is
GRANT,DENY, orCHECK. 0 <= regions[i] < parent.length.- There is at least one
CHECKoperation.
More Pinterest Phone Screen questions
- Shortest Pin Path Through TopicsPHONE SCREEN · Seen Nov 2026
- Top K Pins with Insert and QueryPHONE SCREEN · Seen Nov 2026
- Pins Violation Log QueriesPHONE SCREEN · Seen Nov 2026
- Sparse Matrix Addition and MultiplicationPHONE SCREEN · Seen Nov 2026
- Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Aggregate Matching IPv4 Addresses Across ResponsesPHONE SCREEN · Seen Oct 2026
- Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Shortest Way to Form a Target StringPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Render a Stable Comment HierarchyBobyard · PHONE SCREEN
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Recursive Display SortFigma · PHONE SCREEN · ONSITE INTERVIEW
- Tree-Dependent KnapsackGoogle · PHONE SCREEN
- Nested Todo ListNotion · PHONE SCREEN · ONSITE INTERVIEW
- Delete a Filesystem TreeDatadog · PHONE SCREEN · ONSITE INTERVIEW
- Colored Rooted TreeRubrik · ONSITE INTERVIEW
- Validate BST Node DescriptionsAirbnb · OA
- Rolling MetricsAkuna Capital · OA
- Chain of CommandIMC Trading · OA