Reported May 2026
Snowflakegraph

Effective Role Privileges

Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Snowflake OA. Under 2s to a working solution.
Founder's read

Snowflake reported this one in May 2026, and the statement hands you the whole trick in the first example: role 2 inherits from role 1, which inherits from role 0, so privileges flow down a chain. It's a DAG with up to 2 * 10^5 roles and grants, and the output is a sorted, deduplicated privilege list per role. That's a topological sort with set merging, nothing exotic. The risk is blowing up on big inputs or forgetting duplicates like ["A","A"]. If you freeze during the live OA, StealthCoder runs invisibly as a safety net and gives you the working structure.

The problem

You are given n roles. Role i has a list of direct privileges privileges[i]. You are also given inheritance relations grants, where each pair [u, v] means role v inherits every privilege from role u.
The inheritance graph is a directed acyclic graph. A role's effective privileges are all privileges from its ancestors plus its own direct privileges.
Return the effective privileges for every role. Remove duplicates within each role and return each role's privilege list in lexicographic order.

Function
getEffectivePrivileges(privileges: String[][], grants: int[][]) → String[][]

Examples
Example 1
privileges = [["A"],["B"],["C"]]
grants = [[0,1],[1,2]]
return = [["A"],["A","B"],["A","B","C"]]
Role 1 inherits role 0, and role 2 inherits both role 1 and role 0 transitively.
Example 2
privileges = [["READ"],["WRITE"],["DEPLOY"],["AUDIT"]]
grants = [[0,2],[1,2],[2,3]]
return = [["READ"],["WRITE"],["DEPLOY","READ","WRITE"],["AUDIT","DEPLOY","READ","WRITE"]]
Example 3
privileges = [["A","A"],["A"],[]]
grants = [[0,1],[1,2]]
return = [["A"],["A"],["A"]]

Constraints
1 <= privileges.length <= 2 * 10^5
0 <= grants.length <= 2 * 10^5
Each grant is a pair [u, v] with 0 <= u, v < privileges.length.
The role inheritance graph is a DAG.
Privilege strings are non-empty tokens without spaces.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build the graph with edges u to v, since v inherits from u. Compute in-degrees and run Kahn's algorithm. Give each role a set seeded with its own privileges. When you pop role u, union its set into each child v, then decrement the child's in-degree. When the queue empties, sort each set lexicographically and return. The set handles duplicates like Example 3 for free. The common pitfall is doing DFS from every node and recomputing ancestors, which goes quadratic. Another is copying sets carelessly, so merge into the child instead of rebuilding. Remember roles with no grants still need an entry, even an empty list. Worst-case output size can be large, so don't add extra passes beyond the sort. If you blank on the merge order, StealthCoder is the hedge on the live OA, but the Kahn's skeleton is short enough to memorize tonight.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Effective Role Privileges cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Snowflake's OA.

Snowflake reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Effective Role Privileges FAQ

What's the trick in Effective Role Privileges?+

Process roles in topological order so every parent's final privilege set is complete before you push it to children. Kahn's algorithm does this cleanly. Use sets for dedup, then sort each role's set at the end. That's the whole problem.

How hard is this Snowflake OA question really?+

Medium. The graph is guaranteed acyclic, so no cycle handling. If you know topological sort and set union, it's maybe 30 lines. The difficulty is mostly efficiency on 2 * 10^5 nodes and edges, not cleverness.

Should I use DFS or Kahn's algorithm?+

Either works, but Kahn's is easier to get right here. DFS with memoization also works: compute each role's set from its parents once. Naive DFS from every node without memoization will be too slow at the stated limits.

How do I handle duplicates and ordering?+

Store privileges in a set per role so duplicates vanish, like ["A","A"] in Example 3. Sort only once per role at the end, using standard string comparison. Sorting during every merge wastes time.

How do I prepare for this in 48 hours?+

Write Kahn's algorithm from scratch twice, then add set merging on top. Test on the three examples, including the empty-privilege role and the diamond case where role 2 inherits from two parents. That covers the traps this problem sets.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Snowflake.

OA at Snowflake?
Invisible during screen share
Get it