← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round, one question, graph stuff. Not the worst session I've had there but definitely made me think harder than I expected about cycle detection.

Questions Asked (1)

Q1

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

Algorithms & Data Structures
Author's notes

Classic topological sort / cycle detection problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses and prerequisites as a directed graph and check for cycles using either Kahn's algorithm (BFS topological sort) or DFS with recursion stack. If a topological ordering exists, all courses can be completed; otherwise, a circular dependency prevents completion.

Pro tip: Clarify edge direction early: if course A requires prerequisite B, the edge should go from B to A (prerequisite → dependent) for topological sorting. Also mention that this is essentially cycle detection in a directed graph, which shows you recognize the underlying pattern.

1. Clarify and model the problem

Confirm input format (e.g., numCourses and prerequisite pairs) and edge direction. Build an adjacency list and indegree array to represent the directed graph.

2. Choose a cycle detection algorithm

Select either Kahn's algorithm (BFS topological sort) or DFS with a recursion stack. Explain why the chosen method fits the problem and its trade-offs.

3. Walk through the algorithm

For Kahn's: repeatedly remove nodes with indegree 0 and decrement neighbors' indegrees. For DFS: mark nodes as visiting/visited and detect back edges. Track the number of processed nodes.

4. Determine feasibility and handle edge cases

If all nodes are processed, return true; otherwise, a cycle exists. Discuss edge cases like no prerequisites, disconnected components, and self-loops.

5. Analyze complexity and test

State time and space complexity (O(V+E) for both algorithms). Suggest testing with small examples, including a cycle and a valid DAG.

Key Points to Mention

  • Graph representation: adjacency list and indegree array
  • Topological sorting as the core concept
  • Kahn's algorithm (BFS) vs. DFS with recursion stack
  • Cycle detection in directed graphs
  • Time and space complexity: O(V+E) time, O(V+E) space
  • Edge cases: empty input, no prerequisites, self-loop, disconnected graph

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