← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Snowflake software engineer interview with a graph/scheduling problem that sounds straightforward until you realize they want you to handle the impossible case too. Pretty standard algorithmic round but they pushed on test case design which I wasn't fully ready for.

Questions Asked (1)

Q1

Given a list of courses and their prerequisites, return a valid order in which all courses can be completed. If no valid ordering exists, return an empty array.

Algorithms & Data Structures
Author's notes

I jumped straight to BFS with in-degree tracking, which worked, but I fumbled a bit explaining why I return empty when there's a cycle.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses and prerequisites as a directed graph where edges represent prerequisite relationships. Then perform a topological sort using either Kahn's algorithm (BFS with in-degree tracking) or DFS with cycle detection. If a cycle exists, return an empty array; otherwise, return the topological order.

Pro tip: Clarify edge direction upfront: if course A requires course B, the edge should go from B to A (prerequisite to dependent). Also, mention that you'll handle disconnected graphs and multiple valid orders.

1. Clarify and Model the Problem

Confirm input format (e.g., number of courses and list of prerequisite pairs) and edge direction. Build an adjacency list and in-degree array for each course.

2. Choose Topological Sort Algorithm

Decide between Kahn's algorithm (BFS) or DFS-based topological sort. Both are O(V+E) time and space; Kahn's is often easier to explain and naturally detects cycles.

3. Implement the Algorithm

For Kahn's: initialize a queue with courses having in-degree 0, then repeatedly dequeue and reduce in-degrees of neighbors. For DFS: perform post-order traversal and detect back edges.

4. Detect Cycles and Validate

If the result order does not include all courses, a cycle exists—return an empty array. Otherwise, return the order.

5. Analyze Complexity and Edge Cases

State time and space complexity (O(V+E)). Discuss edge cases: no prerequisites, multiple valid orders, disconnected components, and self-loops.

Key Points to Mention

  • Graph representation: adjacency list and in-degree array
  • Topological sorting algorithms: Kahn's (BFS) and DFS-based
  • Cycle detection: if processed nodes < total nodes, cycle exists
  • Time and space complexity: O(V+E) where V is courses and E is prerequisites
  • Handling disconnected graphs and multiple valid topological orders
  • Edge direction: prerequisite -> dependent course

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