← Questions
Resolve user roles across an account hierarchy
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Jan 2026. It tests trees, permissions and hash map.
Accounts form a tree: an organization has sub-accounts, which can have their own sub-accounts. A user can be granted roles on any account, and a role granted on an account also applies to every account below it. Given the tree and the grants, work out the roles a user has on a given account.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
RoleResolver(parents: dict[str, str | None], grants: list[tuple[str, str, str]])—parents[account]is its parent account, orNonefor a root. Each grant is(user_id, account_id, role). -
roles(user_id, account_id) -> set[str]— the roles granted to the user on the account or on any of its ancestors.
Example
parents = {"root": None, "eu": "root", "fr": "eu", "us": "root"}
grants = [("ana", "root", "viewer"), ("ana", "eu", "admin"),
("bo", "fr", "developer"), ("bo", "root", "viewer")]
roles("ana", "fr") -> {"viewer", "admin"} # from root and eu
roles("ana", "us") -> {"viewer"}
roles("bo", "eu") -> {"viewer"} # fr's grant does not flow up
roles("bo", "fr") -> {"developer", "viewer"}
roles("cy", "fr") -> set()
Constraints
- Up to 10^5 accounts and 10^5 grants; the tree can be deep.
- An unknown account is an error.
Clarifying questions
- Is the hierarchy always a tree, or can an account have several parents?
- Can a role be revoked or overridden lower in the tree?
- How often do queries happen compared with changes to grants and the tree?
- Should the answer also say where each role came from?
What a strong answer covers
- An index of grants by
(user, account), then a walk up the parent chain collecting roles: O(depth) per query. - Precomputing or caching effective roles when queries far outnumber changes, and what invalidates the cache.
- Guarding against a cycle in bad data, and an iterative walk for deep trees.
- Tests for direct grants, inherited grants, siblings that must not leak, and unknown users.
Follow-ups
- Add deny grants: a deny lower in the tree removes a role inherited from above.
- Roles imply other roles (
adminincludesdeveloper, which includesviewer). - List every account where a user holds a given role.
- An account moves to a new parent. What has to change?
Where it's asked
- Stripe · Technical phone screen · Last asked Jan 202660 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
