Problem · Tree

RBAC Role Resolver - Users for Account with Role Filter

Learn this problem
MediumStripe logoStripeFULLTIMEPHONE SCREEN
See Stripe hiring insights

Problem statement

This continues the RBAC system over a tree of accounts (Organization → Workspace → Team). Find the users who have access to a given account and optionally filter them by required roles.

Inputs: accounts (a String[] of "accountId,parent" where a root uses null as parent), assignments (a String[] of "userId,accountId,role"), accountId (the account to query), and roleFilters (a String[] of required roles).

A user has access to an account if they are assigned any role on that account or on any of its ancestors (roles inherit downward). When roleFilters is non-empty, keep only users who have all of the required roles on that account (counting inherited roles); when roleFilters is empty, return every user with any access.

Return the matching user ids as a String[] sorted alphabetically (no duplicates).

Function

getUsersForAccount(accounts: String[], assignments: String[], accountId: String, roleFilters: String[]) → String[]

Examples

Example 1

accounts = ["org_1,null", "wksp_1,org_1"]assignments = ["usr_1,org_1,admin", "usr_1,wksp_1,editor", "usr_2,wksp_1,editor", "usr_3,wksp_1,viewer"]accountId = "wksp_1"roleFilters = []return = ["usr_1", "usr_2", "usr_3"]
With no filter, every user with access to wksp_1 is returned: usr_1 (admin inherited from org_1 plus editor on wksp_1), usr_2 (editor), usr_3 (viewer).

Example 2

accounts = ["org_1,null", "wksp_1,org_1"]assignments = ["usr_1,org_1,admin", "usr_1,wksp_1,editor", "usr_2,wksp_1,editor", "usr_3,wksp_1,viewer"]accountId = "wksp_1"roleFilters = ["editor"]return = ["usr_1", "usr_2"]
Filtering by editor: usr_1 and usr_2 are editors on wksp_1; usr_3 is only a viewer, so excluded.

Example 3

accounts = ["org_1,null", "wksp_1,org_1"]assignments = ["usr_1,org_1,admin", "usr_1,wksp_1,editor", "usr_2,wksp_1,editor", "usr_3,wksp_1,viewer"]accountId = "wksp_1"roleFilters = ["admin", "editor"]return = ["usr_1"]
Requiring both admin AND editor: only usr_1 qualifies (admin inherited from org_1 plus editor on wksp_1). usr_2 has editor but not admin; usr_3 has neither.

Constraints

  • Each account entry is "accountId,parent" (root parent null); one parent per account, no cycles.
  • Each assignment is "userId,accountId,role"; roles inherit downward.
  • A user has access to an account via a role on it or any ancestor.
  • With a non-empty roleFilters, keep only users having all required roles (inherited counted); empty filter returns all users with access.
  • Return the alphabetically-sorted, de-duplicated String[] of user ids.

More Stripe problems

drafts saved locally
public String[] getUsersForAccount(String[] accounts, String[] assignments, String accountId, String[] roleFilters) {
  // write your code here
}
accounts["org_1,null", "wksp_1,org_1"]
assignments["usr_1,org_1,admin", "usr_1,wksp_1,editor", "usr_2,wksp_1,editor", "usr_3,wksp_1,viewer"]
accountId"wksp_1"
roleFilters[]
expected["usr_1", "usr_2", "usr_3"]
checking account