← Pinterest Interview InsightsMachine Learning Engineer

Pinterest·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026

Summary

Pinterest MLE interview that was basically one meaty coding design problem about access control with a hierarchy. The follow-up complexity requirements were where things got interesting and a little stressful.

Questions Asked (1)

Q1

Design an access-control class for advertisers and a group hierarchy (e.g., world -> country -> city), where children inherit access from parent groups. Implement grant_access, revoke_access, and check_access methods, then optimize for O(1) grants and revokes with O(depth) check traversal using a tree-backed structure.

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

Started with a flat dict mapping advertiser IDs to sets of groups, which felt fine until they asked about inheritance.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a tree-backed structure where each group node stores access grants for advertisers. Implement grant/revoke as O(1) operations by updating the node's grant set, and check_access by traversing from the node up to the root, aggregating grants with inheritance semantics. Discuss trade-offs and potential optimizations like caching or path compression.

Pro tip: Emphasize that O(1) grant/revoke and O(depth) check are achieved by storing grants at the node level and inheriting upward, but also mention that this design may require careful handling of revocations (e.g., using a tombstone or deny list) to maintain correctness.

1. Clarify Requirements and Constraints

Ask about expected scale, read/write ratio, consistency requirements, and whether revocations should override grants. Confirm that O(1) grant/revoke and O(depth) check are hard requirements.

2. Design Data Structures

Propose a tree where each node represents a group and stores a set of advertiser IDs with access. For O(1) grant/revoke, use a hash set per node. For inheritance, a child inherits all grants from ancestors.

3. Implement Core Methods

grant_access(advertiser, group): add advertiser to group's set. revoke_access: remove from set. check_access(advertiser, group): traverse from group up to root, checking if advertiser is in any ancestor's set.

4. Address Revocation and Inheritance Semantics

Discuss how to handle revocations that should override inherited grants. Consider using a deny set or tombstone per node, and explain how check_access would incorporate both allow and deny sets.

5. Analyze Trade-offs and Optimizations

Compare with alternative designs (e.g., materialized paths, caching). Discuss how to optimize check_access with memoization or path compression, and the impact on grant/revoke complexity.

Key Points to Mention

  • Tree-backed structure with each node storing a set of advertiser IDs for O(1) grant/revoke.
  • Inheritance via upward traversal: check_access walks from node to root, aggregating grants.
  • Handling revocations: use deny sets or tombstones to override inherited grants, ensuring correctness.
  • Time complexity: grant/revoke O(1), check O(depth) where depth is tree height.
  • Space complexity: O(total grants) across all nodes, potentially large but acceptable for many use cases.
  • Trade-offs: simplicity vs. revocation complexity; caching can reduce check time but may complicate updates.

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