← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Snowflake software engineer coding round with a graph traversal problem. Pretty clean problem once you figure out what they're actually asking, but the setup takes a second to parse.

Questions Asked (1)

Q1

You're given a list where each index represents the privileges belonging to a role, and a list of grants where one role inherits from another (directed edges). Compute the full set of privileges each role ends up with after inheriting from all its ancestors.

Algorithms & Data Structures
Author's notes

First thing I did was ask if cycles were possible.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the roles and grants as a directed graph, then compute the transitive closure of privileges using either DFS with memoization or topological sorting. For each role, union its own privileges with those of all ancestors, handling cycles if present.

Pro tip: Clarify whether the graph is a DAG or may contain cycles; if cycles are possible, use SCC condensation or iterative DFS with visited sets to avoid infinite loops. Also discuss trade-offs between time and space, and mention that bitsets can optimize union operations for large privilege sets.

1. Clarify inputs and constraints

Confirm the representation: privileges per role, grants as directed edges (from child to parent or vice versa), and whether cycles are possible. Ask about expected scale to choose an efficient algorithm.

2. Model as a graph problem

Treat roles as nodes and grants as directed edges. The goal is to compute, for each node, the union of privileges of all nodes reachable via reverse edges (ancestors).

3. Choose an algorithm

If the graph is a DAG, use topological order and propagate privilege sets from parents to children. If cycles exist, first condense SCCs or use DFS with memoization and cycle detection.

4. Implement and optimize

Use sets or bitsets for efficient unions. For large graphs, consider iterative DFS to avoid recursion limits, and memoize results to avoid recomputation.

5. Analyze complexity and test

Discuss time and space complexity (e.g., O(V+E) times the cost of set union). Test with edge cases: no grants, cycles, multiple parents, and large privilege sets.

Key Points to Mention

  • Graph representation: adjacency list for grants, with direction indicating inheritance (child inherits from parent).
  • Transitive closure: each role's privileges are the union of its own and all ancestors' privileges.
  • Cycle handling: detect and condense strongly connected components or use visited sets to avoid infinite loops.
  • Algorithm choice: topological sort with DP for DAGs, or DFS with memoization for general graphs.
  • Optimization: use bitsets for fast union operations when privilege sets are large and dense.
  • Complexity analysis: time O(V+E) times union cost, space O(V * P) where P is average privileges per role.

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