Design Hierarchical Permission Checks
Company: Pinterest
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of hierarchical access control, tree data structures, and permission inheritance, testing competencies in data modeling and algorithmic reasoning.
Constraints
- 1 <= number of groups <= 10^5
- 0 <= number of operations <= 10^5
- The parent mapping forms a valid tree with exactly one root
- Every group_id used in operations exists in the parent mapping
- grant_access and revoke_access should be O(1) average time; check_access should be O(depth of the tree)
Examples
Input: ({'World': None, 'US': 'World', 'NYC': 'US', 'SF': 'US', 'CA': 'World'}, [('grant', 'adv1', 'US'), ('check', 'adv1', 'NYC'), ('check', 'adv1', 'US'), ('check', 'adv1', 'CA')])