← Amazon Interview Insights

Amazon·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Did a coding round for an MLE role at Amazon. One question, graph-based, similar to the classic Course Schedule problem. Pretty standard for this type of role but still stressful in the moment.

Questions Asked (1)

Q1

Given a set of courses with prerequisites, determine if it's possible to complete all courses (detect a cycle in a directed graph).

Algorithms & Data Structures
Author's notes

Classic topological sort or cycle detection problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses as a directed graph where edges represent prerequisites, then detect cycles using either Kahn's algorithm (BFS topological sort) or DFS with recursion stack. Clearly explain the graph construction, the chosen algorithm, and its time/space complexity.

Pro tip: Mention that this is a classic topological sort problem and that Kahn's algorithm is often preferred in production for its iterative nature and ability to detect cycles early. Also, relate it to real-world dependency resolution in ML pipelines or build systems.

1. Clarify and Model the Problem

Confirm that courses are nodes and prerequisites are directed edges. Ask about input format (e.g., number of courses, list of prerequisite pairs) and edge cases like duplicate edges or self-loops.

2. Choose an Algorithm

Select either Kahn's algorithm (BFS-based topological sort) or DFS with cycle detection. Briefly justify your choice based on simplicity, iterative nature, or early termination.

3. Walk Through the Algorithm

Explain step-by-step how the algorithm works: for Kahn's, compute in-degrees, use a queue, and count processed nodes; for DFS, track visited and recursion stack states.

4. Analyze Complexity and Edge Cases

State time and space complexity (O(V+E) for both). Discuss handling of disconnected graphs, empty input, and cycles that don't include all nodes.

5. Discuss Extensions and Applications

Mention how to return the actual course order (topological sort) and relate the problem to dependency resolution in ML pipelines, build systems, or task scheduling.

Key Points to Mention

  • Graph representation: adjacency list for efficiency
  • Kahn's algorithm: in-degree array, queue, and processed count
  • DFS approach: visited set and recursion stack for cycle detection
  • Time and space complexity: O(V+E) time, O(V+E) space
  • Handling disconnected graphs and multiple components
  • Real-world relevance: dependency resolution in ML pipelines or build systems

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