Design Efficient Multi-Level Access Control System
Company: Pinterest
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates understanding of hierarchical access control models, efficient path-based permission representation, and algorithmic design for fast membership checks.
Constraints
- 1 <= len(ops) <= 100000
- Each op is ["add", pattern] or ["check", path]
- Paths/patterns start with '/' and have segments separated by '/'
- Wildcard '*' matches exactly one segment
- Wildcard '**' matches zero or more trailing segments and may appear only as the final segment of a pattern
- No redundant slashes; segments are non-empty (root '/' has zero segments)
- Total length of all strings <= 1e6
Hints
- Build a trie keyed by path segments.
- Mark nodes where a pattern ends (terminal) and where a pattern with trailing '**' ends (starstar).
- During check, perform BFS/DFS over trie states (node, index), following exact and '*' edges; if you encounter starstar at any visited node, it's an immediate match.