← Netflix Interview Insights

Netflix·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Netflix coding screen, graph problem that looks straightforward until you realize you need to think in terms of topological sort and DAG levels. The follow-up they mentioned is a harder variant with a per-semester course cap, which I hadn't prepped for.

Questions Asked (2)

Q1

Given n courses labeled 1 through n and a list of prerequisite pairs, find the minimum number of semesters needed to complete all courses if you can take any number of courses per semester (as long as prerequisites are done). Return -1 if it's impossible.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was BFS and I went with it, which was right, but I fumbled explaining why the number of BFS levels equals the answer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses and prerequisites as a directed graph, then use topological sorting to detect cycles and compute the longest path (critical path) which represents the minimum semesters. If a cycle exists, return -1; otherwise, the length of the longest path gives the answer.

Pro tip: Emphasize that this is a longest path problem in a DAG, not just topological sort; also discuss how to handle large graphs efficiently with Kahn's algorithm or DFS, and mention edge cases like disconnected graphs.

1. Understand the problem

Clarify that courses can be taken in parallel if prerequisites are met, so the minimum semesters equals the maximum number of courses in any prerequisite chain (longest path).

2. Model as a graph

Represent courses as nodes and prerequisites as directed edges from prerequisite to dependent course. This forms a directed graph.

3. Detect cycles

Use topological sorting (Kahn's algorithm or DFS) to check for cycles. If a cycle exists, it's impossible to complete all courses, so return -1.

4. Compute longest path

During topological sort, compute the longest distance (in terms of semesters) from any source node to each node. The maximum distance is the minimum number of semesters.

5. Return result

If no cycle, return the maximum distance; otherwise, return -1. Discuss time and space complexity: O(V+E) time, O(V+E) space.

Key Points to Mention

  • Graph representation: adjacency list for efficiency
  • Topological sorting using Kahn's algorithm (BFS) or DFS
  • Cycle detection: if topological sort doesn't include all nodes, there's a cycle
  • Longest path in DAG: dynamic programming with topological order
  • Time complexity: O(V+E) where V is number of courses and E is number of prerequisites
  • Edge cases: disconnected graph, multiple components, no prerequisites

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

Q2

Follow-up: how would you solve the same problem if you could only take at most K courses per semester?

Algorithms & Data Structures
Author's notes

Did not have a clean answer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the original problem (likely course scheduling with prerequisites) and the new constraint: at most K courses per semester. Then, model it as a graph problem and adapt the algorithm to respect the per-semester limit, discussing trade-offs between greedy and optimal approaches.

Pro tip: Netflix values scalability and real-world constraints, so mention how you'd handle large inputs and edge cases like K=1 or K greater than the number of courses. Also, proactively discuss time/space complexity and potential optimizations.

1. Clarify the problem

Restate the original problem (e.g., course scheduling with prerequisites) and confirm the new constraint: at most K courses per semester. Ask about goals: minimize semesters, check feasibility, or maximize courses?

2. Model as a graph

Represent courses as nodes and prerequisites as directed edges. The problem becomes topological sorting with a per-level (semester) capacity constraint.

3. Adapt algorithm

Use a modified topological sort (e.g., Kahn's algorithm) where each semester you can take up to K available courses. If more than K are available, choose which to take (e.g., prioritize by some heuristic).

4. Analyze complexity and edge cases

Discuss time/space complexity (O(V+E) for graph traversal). Handle edge cases: K=1 (sequential), K >= max available (original problem), cycles (impossible), and disconnected graphs.

5. Discuss trade-offs and optimizations

If the goal is to minimize semesters, the greedy choice of taking any K available courses may not be optimal; mention that finding the optimal schedule might require more complex approaches (e.g., binary search on semesters with feasibility check).

Key Points to Mention

  • Topological sorting with capacity constraints
  • Greedy vs. optimal scheduling (when greedy fails)
  • Time and space complexity analysis
  • Edge cases: K=1, K large, cycles, disconnected components
  • Real-world scalability and Netflix's engineering culture
  • Potential use of priority queues or heuristics for course selection

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