← Pinterest Interview Insights

Pinterest·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Pinterest MLE interview focused on a system design coding problem around access control with group hierarchies. The problem escalated from a simple dictionary approach into a proper tree traversal, which is where things got interesting.

Questions Asked (1)

Q1

Design and implement an access-control class for advertisers and a group hierarchy (e.g., world > country > city), where children inherit access from parent groups. The API needs grant_access, revoke_access, and check_access methods. Start with a flat dictionary, then optimize to a tree-backed implementation where grant and revoke are O(1) and check_access walks up the tree in O(depth).

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to just store a set of (advertiser, group) pairs and call it a day.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and defining the API, then implement a flat dictionary solution to establish a baseline. Next, design a tree-backed structure where each node stores its own access set and children, enabling O(1) grant/revoke and O(depth) check_access by walking up to the root. Discuss trade-offs, optimizations, and test cases.

Pro tip: Emphasize the trade-off between simplicity and performance: the flat dictionary is easy but slow for checks, while the tree is efficient but requires careful handling of inheritance and revocation. Also, mention that in practice, caching or precomputing effective permissions can further optimize check_access for read-heavy workloads.

1. Clarify Requirements and API

Ask questions to understand the scope: Are groups hierarchical? Can advertisers belong to multiple groups? What are the expected read/write ratios? Define the methods: grant_access(advertiser, group), revoke_access(advertiser, group), check_access(advertiser, group).

2. Baseline Flat Dictionary Implementation

Propose a simple solution using a dictionary mapping group IDs to sets of advertisers. Explain that grant and revoke are O(1) but check_access requires traversing all ancestors, leading to O(depth) per check if hierarchy is considered, or O(1) if flat but ignoring inheritance.

3. Design Tree-Backed Structure

Describe a tree where each node represents a group and stores a set of advertisers with direct access. Children inherit access from parents. grant_access adds to the node's set; revoke_access removes from the node's set. check_access walks up from the given group to the root, checking each node's set.

4. Analyze Complexity and Trade-offs

Explain that grant and revoke are O(1) because they only modify the node's set. check_access is O(depth) because it may traverse from the node to the root. Discuss memory usage and potential optimizations like caching effective permissions or using bitsets.

5. Discuss Extensions and Testing

Mention handling of multiple parents (DAG) if needed, concurrency, and persistence. Outline test cases: inheritance, revocation, deep hierarchies, and edge cases like root access.

Key Points to Mention

  • Inheritance: children automatically inherit access from ancestors, so check_access must consider the entire path to the root.
  • O(1) grant/revoke: operations only modify the target group's access set, not descendants.
  • O(depth) check_access: walk up the tree, checking each ancestor's set; worst-case depth is tree height.
  • Trade-offs: flat dictionary is simple but inefficient for checks; tree is efficient but requires more complex data structures.
  • Optimization: cache effective permissions per advertiser-group pair or use memoization to speed up repeated checks.
  • Edge cases: root access, revoking inherited access, multiple group memberships, and concurrent modifications.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.