← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Snowflake software engineer interview that went deep on graph algorithms and scheduling. Three connected parts to one problem, and by the third part I was genuinely winging it.

Questions Asked (3)

Q1

You have N services with dependency relationships (u must start before v). Given these pairs, produce a valid startup order or detect and report a cycle if one exists.

Algorithms & Data Structures
Author's notes

Topological sort, so I knew the shape of it pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the services and dependencies as a directed graph, then perform a topological sort using Kahn's algorithm (BFS) or DFS. If the sort processes all nodes, return the order; otherwise, a cycle exists and can be reported by identifying nodes with remaining in-degree or using DFS back edges.

Pro tip: Mention that Kahn's algorithm naturally detects cycles when the output size is less than N, and you can optionally return the cycle path for debugging. Also note that if multiple valid orders exist, any is acceptable unless a specific tie-breaking rule is given.

1. Clarify requirements and edge cases

Confirm whether the graph is directed, if multiple valid orders are acceptable, and how to handle duplicate edges or disconnected components. Ask if the output should be any valid order or a specific one (e.g., lexicographically smallest).

2. Build the graph representation

Create an adjacency list for outgoing edges and an in-degree array for each node. Iterate through the given pairs (u, v) to populate these structures.

3. Perform topological sort

Use Kahn's algorithm: enqueue all nodes with in-degree 0, then repeatedly dequeue a node, add it to the order, and decrement the in-degree of its neighbors, enqueuing any that reach 0. Alternatively, use DFS with a recursion stack to detect cycles.

4. Detect and report cycles

If the topological order contains fewer than N nodes, a cycle exists. For Kahn's, the remaining nodes with non-zero in-degree are part of cycles. For DFS, a back edge indicates a cycle; you can reconstruct the cycle path if needed.

5. Analyze complexity and discuss optimizations

State that both approaches run in O(N + E) time and O(N + E) space. Mention that Kahn's is often preferred for cycle detection because it's iterative and avoids recursion depth issues.

Key Points to Mention

  • Directed graph modeling: services as nodes, dependencies as directed edges (u -> v means u must start before v).
  • Topological sort algorithms: Kahn's (BFS-based) and DFS-based, with their trade-offs.
  • Cycle detection: Kahn's algorithm detects cycles when processed nodes < N; DFS detects back edges.
  • Time and space complexity: O(N + E) for both algorithms.
  • Handling edge cases: empty input, self-loops, duplicate edges, disconnected components.
  • Optional: returning the actual cycle path for debugging or lexicographically smallest order if required.

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

Q2

Using the same dependency graph, group the services into startup layers where all services with no unmet dependencies form the first layer, then the next set, and so on.

Algorithms & Data Structures
Author's notes

This is basically BFS levels on the topo sort, which flows naturally from part one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a topological sort problem where you need to group nodes into layers based on their dependencies. Use Kahn's algorithm: repeatedly find all nodes with in-degree zero, add them as the current layer, remove them, and update in-degrees of their neighbors. Continue until all nodes are processed.

Pro tip: Mention that this is essentially a level-order topological sort, and clarify that within each layer, the order of services doesn't matter—only the grouping does. Also, be prepared to discuss how to handle cycles if they exist.

1. Compute in-degrees

Calculate the in-degree (number of unmet dependencies) for each service by iterating over all edges. Initialize a queue with all services that have in-degree zero.

2. Process layers iteratively

While the queue is not empty, record the current size as the layer size, then process exactly that many nodes. For each node, add it to the current layer and decrement the in-degree of its neighbors; if a neighbor's in-degree becomes zero, add it to the queue.

3. Collect layers

After processing each batch, add the current layer to the result list. Continue until the queue is empty.

4. Handle cycles

If the total number of processed nodes is less than the total number of services, a cycle exists. In that case, either report the cycle or handle it based on requirements.

Key Points to Mention

  • Topological sorting using Kahn's algorithm
  • In-degree calculation and zero in-degree queue
  • Layer-by-layer processing (BFS-like approach)
  • Time complexity O(V+E) and space complexity O(V+E)
  • Handling cycles and reporting if not all nodes are processed
  • Clarifying that within a layer, order does not matter

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

Q3

Each service has a startup time and you have K CPU cores available. Schedule the startups to minimize total completion time while respecting the dependency constraints. Describe your algorithm, its complexity, and any practical heuristics for parallelism.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

This is where things got uncomfortable.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a DAG scheduling problem with K identical machines, then propose a list-scheduling algorithm using critical-path priorities (e.g., HLF or CP) to minimize makespan. Analyze complexity as O(V log V + E) for priority computation and O(V log K) for scheduling, and discuss practical heuristics like work-stealing and dynamic priority adjustment.

Pro tip: Acknowledge that the problem is NP-hard in general, so focus on heuristics and mention that Snowflake's real-world systems often use hybrid approaches combining static priorities with runtime load balancing.

1. Clarify assumptions and constraints

Confirm that services form a DAG, startup times are known, and K cores are identical. Ask if preemption is allowed or if services can be split.

2. Define the objective and complexity

State that minimizing total completion time (makespan) with dependencies is NP-hard. For K=1, it's topological order; for K>1, it's P|prec|Cmax.

3. Propose a list-scheduling algorithm

Compute each node's critical path length (longest path to sink). Use a priority queue to always schedule the ready node with the highest critical path on an available core.

4. Analyze complexity and optimality

Time: O(V log V + E) for critical paths, O(V log K) for scheduling. Space: O(V+E). Mention that list scheduling gives a 2-approximation for makespan.

5. Discuss practical heuristics and trade-offs

Mention dynamic priority updates, work-stealing, batching small tasks, and handling stragglers. Discuss when to prefer throughput vs. latency.

Key Points to Mention

  • Critical path method (CPM) and its role in prioritizing tasks
  • List scheduling with HLF (Highest Level First) or CP priority
  • Complexity analysis: O(V log V + E) for DAG processing, O(V log K) for scheduling
  • Approximation ratio: list scheduling is 2-approximate for makespan
  • Practical heuristics: work-stealing, dynamic re-prioritization, and handling heterogeneous startup times
  • Trade-offs between static scheduling and runtime adaptation in distributed systems

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