← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Snowflake coding round, got a graph/scheduling problem that looked like a topological sort question but had this extra batch-timing twist I wasn't fully ready for.

Questions Asked (1)

Q1

You have a set of courses with prerequisites forming a directed graph, and each course has a completion time. Courses with all prerequisites met can run in parallel as a batch, but you must wait for the entire batch to finish before starting the next one. The time per batch is the max course time in that batch. Return the total time to finish all courses, or -1 if there's a cycle.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I got the topological sort part pretty quickly, BFS with in-degree tracking, standard stuff.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses as a directed graph and use topological sorting (Kahn's algorithm) to process courses in batches. For each batch, compute the maximum completion time among courses with zero in-degree, add it to the total time, and update in-degrees of dependent courses. If not all courses are processed, return -1 for a cycle.

Pro tip: Mention that this is a variation of the classic Course Schedule problem, but with weighted batches. Emphasize that the key insight is to process level by level (BFS) rather than one by one, and that using a queue naturally handles parallel execution.

1. Clarify and Model the Problem

Confirm that courses in the same batch run in parallel and the batch time is the maximum course time. Represent the prerequisites as a directed graph with adjacency lists and compute in-degrees for each course.

2. Initialize Data Structures

Use a queue to store courses with zero in-degree (ready to take). Maintain an array for in-degrees and a variable to accumulate total time.

3. Process Batches with BFS

While the queue is not empty, process all courses currently in the queue as one batch. For each course, update the in-degrees of its neighbors; if a neighbor's in-degree becomes zero, add it to the next batch queue. Track the maximum course time in the current batch and add it to the total time.

4. Detect Cycles and Return Result

After processing, if the number of courses taken is less than the total number of courses, a cycle exists, so return -1. Otherwise, return the accumulated total time.

Key Points to Mention

  • Topological sorting using Kahn's algorithm (BFS) to handle dependencies and detect cycles.
  • Batch processing: grouping courses with zero in-degree at each step and taking the maximum time.
  • Time complexity: O(V + E) where V is number of courses and E is number of prerequisites.
  • Space complexity: O(V + E) for graph representation and auxiliary data structures.
  • Cycle detection: if the number of processed courses is less than V, return -1.
  • Edge cases: empty graph, single course, disconnected components, and courses with no prerequisites.

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