← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round, one question on course scheduling. Pretty standard graph problem if you've seen it before, but the pressure of doing it live is a different thing entirely.

Questions Asked (1)

Q1

Given a number of courses and a list of prerequisite pairs, determine whether it's possible to complete all courses without getting stuck in a circular dependency.

Algorithms & Data Structures
Author's notes

Cycle detection in a directed graph, basically.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses and prerequisites as a directed graph where an edge from course A to course B means A is a prerequisite for B. The problem reduces to detecting whether this graph contains a cycle; if it does, completing all courses is impossible. Use either Kahn's algorithm (BFS-based topological sort) or DFS with recursion stack to detect cycles efficiently.

Pro tip: Clarify edge direction upfront: whether the edge goes from prerequisite to course or vice versa, as this affects the algorithm's implementation. Also, mention that Kahn's algorithm naturally provides a topological order if no cycle exists, which can be a bonus for scheduling.

1. Model as a Graph

Represent courses as nodes and prerequisites as directed edges. Decide on edge direction (e.g., prerequisite -> course) and build an adjacency list.

2. Choose Cycle Detection Method

Select either Kahn's algorithm (BFS with in-degree tracking) or DFS with a recursion stack. Explain why the chosen method is suitable.

3. Implement the Algorithm

For Kahn's: compute in-degrees, enqueue nodes with in-degree 0, process and decrement neighbors. For DFS: traverse with visited and recursion stack arrays to detect back edges.

4. Determine Feasibility

If all nodes are processed (Kahn's) or no cycle is found (DFS), return true; otherwise, return false. Optionally, return the topological order if needed.

5. Analyze Complexity

State that both methods run in O(V + E) time and O(V + E) space, where V is the number of courses and E is the number of prerequisite pairs.

Key Points to Mention

  • Directed graph representation with adjacency list
  • Cycle detection via topological sorting (Kahn's algorithm) or DFS with recursion stack
  • In-degree calculation and queue processing for Kahn's algorithm
  • Visited and recursion stack states for DFS approach
  • Time and space complexity: O(V + E)
  • Handling edge cases: no prerequisites, disconnected components, self-loops

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