← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Snowflake coding interview with a graph/scheduling problem that looks like a topological sort question but has a twist on how time accumulates across batches. Not the hardest problem I've seen but the batch timing rule tripped me up for a bit.

Questions Asked (1)

Q1

Given a set of courses with prerequisites and individual completion times, courses with satisfied prerequisites can be started in parallel as a batch. You must wait for the entire batch to finish before moving to the next one, so each batch takes as long as its slowest course. Find the total time to complete all courses, or return -1 if a cycle makes it impossible.

Algorithms & Data StructuresSystem Design
Author's notes

My first instinct was just BFS with level-by-level traversal, which is the right skeleton.

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 with level-by-level processing (Kahn's algorithm) to group courses into batches. For each batch, compute the maximum completion time among its courses and accumulate these maxima to get the total time. If not all courses are processed, a cycle exists, so return -1.

Pro tip: Clarify that the batch time is determined by the slowest course, so you must take the max per batch, not sum individual times. Also, mention that this approach naturally detects cycles and runs in O(V+E) time, which is optimal.

1. Model as a Graph

Represent courses as nodes and prerequisites as directed edges. Compute the in-degree (number of prerequisites) for each course.

2. Initialize and Process Batches

Use a queue to process courses with in-degree 0. For each batch, collect all such courses, compute the maximum completion time among them, and add it to the total time.

3. Update Dependencies

For each course in the current batch, decrement the in-degree of its dependent courses. If any dependent's in-degree becomes 0, add it to the next batch.

4. Detect Cycles and Return Result

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

Key Points to Mention

  • Topological sorting with Kahn's algorithm for level-by-level processing
  • Batch time is the maximum completion time among courses in the batch
  • Cycle detection by comparing processed count with total courses
  • Time complexity O(V+E) and space complexity O(V+E)
  • Handling of courses with no prerequisites (initial batch)
  • Edge cases: empty course list, single course, multiple disconnected components

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