← Meta Interview Insights

Meta·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Meta MLE technical screen focused entirely on graph traversal and topological sort. Pretty standard stuff for the role but they pushed hard on the tradeoffs discussion at the end, which I wasn't fully prepared for.

Questions Asked (2)

Q1

Given a directed graph of package dependencies as an adjacency list, implement a function that returns a valid installation order for a list of packages, or signals that no valid order exists if there's a cycle.

Algorithms & Data Structures
Author's notes

I jumped straight to DFS which was the right call, but fumbled the cycle detection part for a minute.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a topological sort on a directed graph. Use Kahn's algorithm (BFS with in-degree tracking) to produce a valid installation order, and detect cycles if not all nodes are processed. Alternatively, use DFS with recursion stack for cycle detection and post-order reversal.

Pro tip: Clarify assumptions about input: whether the graph is guaranteed to be a DAG, if there are multiple valid orders, and if the function should return any valid order or a specific one. Also, discuss handling of disconnected components and large graphs.

1. Understand the problem and constraints

Restate the problem: given a directed graph of package dependencies, return a valid installation order or detect a cycle. Ask clarifying questions about input format, graph size, and expected output.

2. Choose an algorithm

Select between Kahn's algorithm (BFS) and DFS-based topological sort. Explain the trade-offs: Kahn's is iterative and naturally detects cycles, while DFS uses recursion and can be simpler to implement.

3. Implement the algorithm

For Kahn's: compute in-degrees, use a queue to process nodes with zero in-degree, and build the order. For DFS: perform depth-first search, track visited and recursion stack, and append nodes in post-order.

4. Detect cycles and handle edge cases

If using Kahn's, check if the order contains all nodes; if not, a cycle exists. For DFS, detect back edges. Discuss edge cases: empty graph, single node, disconnected components, self-loops.

5. Analyze complexity and test

State time and space complexity: O(V+E) for both approaches. Walk through a small example to verify correctness, and mention potential optimizations or alternative approaches.

Key Points to Mention

  • Topological sorting is the core concept for dependency resolution.
  • Kahn's algorithm uses in-degree and BFS; DFS uses recursion stack for cycle detection.
  • Cycle detection is crucial: if the graph has a cycle, no valid installation order exists.
  • Time complexity is O(V+E) and space complexity is O(V+E) for both algorithms.
  • Handling disconnected components: the algorithm should process all nodes.
  • Multiple valid orders may exist; the function can return any valid one.

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

Q2

Walk through the tradeoffs between iterative and recursive DFS for this problem, including stack overflow risks and complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This part tripped me up more than the coding.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the problem and the two DFS implementations, then systematically compare them across time/space complexity, stack overflow risk, and practical performance. Conclude with a recommendation based on the problem constraints and environment (e.g., Python recursion limit).

Pro tip: Mention that Python's default recursion limit (~1000) and lack of tail-call optimization make iterative DFS safer for large graphs, but recursive code is often more readable and less error-prone for small inputs.

1. Define the problem and DFS variants

Briefly restate the problem (e.g., graph traversal, tree path) and clarify what iterative and recursive DFS mean in this context.

2. Compare time and space complexity

State that both have O(V+E) time, but space differs: recursive uses call stack O(h) where h is max depth, iterative uses explicit stack O(h) as well, but with different constant factors and memory overhead.

3. Discuss stack overflow risks

Explain that recursive DFS can cause stack overflow for deep graphs (e.g., linked list-like trees) due to limited call stack, while iterative DFS avoids this by using heap-allocated stack.

4. Consider practical factors

Mention language-specific limits (e.g., Python recursion limit), readability, debugging ease, and performance overhead of function calls vs explicit stack operations.

5. Recommend based on constraints

Conclude with a recommendation: use iterative for large/depth-unknown graphs or in languages with low recursion limits; use recursive for simplicity when depth is bounded.

Key Points to Mention

  • Time complexity: both O(V+E) for graph traversal.
  • Space complexity: recursive uses call stack O(h), iterative uses explicit stack O(h), but iterative may have higher constant factor due to stack object overhead.
  • Stack overflow: recursive can overflow for deep graphs; iterative avoids this by using heap memory.
  • Python recursion limit (~1000) and lack of tail-call optimization.
  • Readability and maintainability: recursive often cleaner but iterative more robust.
  • Performance: function call overhead in recursion vs manual stack operations.

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