def can_finish(num_courses: int, prerequisites: list) -> bool:
The round: 16 reports between October 2025 and September 2026, from intern, new-grad, SDE II, L5, MLE and senior Applied Scientist loops, in phone screens and onsite coding rounds. Most are LeetCode 207 and 210 (Course Schedule I and II), either as written or with an Amazon story on top: order tasks that have prerequisites, build a package after its dependencies, find the services hit when some go down. Several reports describe rounds that open with leadership-principle questions and leave the rest of the hour for code. One intern candidate notes that Amazon interviewers do not run the code, so explain the approach before writing it.
The page has four graded parts. Parts 2 to 4 are follow-ups reports describe after the base question.
Input (every part): prerequisites is a list of pairs [a, b] meaning b must be taken before a (LeetCode's convention). Courses (or tasks) are numbered 0 to n - 1. The tests use no repeated pairs and no course that is its own prerequisite.
Part 1 — can every course be finished?
def can_finish(num_courses: int, prerequisites: list) -> bool: ...
True if some order takes every course after all of its prerequisites, False if a cycle makes that impossible (LeetCode 207).Reported variants (not graded)
install() that installs only itself; write installWithDependencies(package) so every dependency is installed first, and detect cyclic dependencies. In the same candidate's onsite, the question was the build order for one target package (it plus everything it needs) with a DFS that keeps a visiting set and a visited set. Not graded; the Solution has a sketch.In a bar-raiser round this was the first follow-up after the candidate solved Part 1 with the in-degree queue (BFS). A task-ordering version asked for a valid execution order from the start. Standard answer: in Kahn's algorithm, append each course as it leaves the queue; if fewer than n courses come out, a cycle blocks the rest and the answer is an empty list (Part 2). A DFS alternative appends each course after all of its prerequisites are finished.
The bar-raiser candidate answered with DFS and three-colour marking: reaching a grey (in-progress) course means a cycle, and walking back along the recursion stack recovers it. They ran out of time to code it and only explained the idea. Standard answer: keep a parent pointer (or the current path) during the DFS; when an edge reaches a course still on the path, read the path from that course to the current one (Part 3).
Reports record this being asked in an SDE II phone screen, a new-grad round and a build-order onsite. One candidate answered O(m + n), with m the number of prerequisite pairs and n the number of courses; the build-order report gives O(V + E) time and O(V + E) space. Standard answer: O(V + E) time, and O(V + E) space for the adjacency list plus in-degrees or DFS state.
In an SDE II phone screen the interviewer repeatedly checked whether the queue traversal was DFS or BFS; the report warns that calling it DFS draws repeated "Are you sure?". A new-grad candidate was asked about the difference between BFS and DFS. Standard answer: processing zero-in-degree courses from a queue is BFS (Kahn's algorithm); DFS uses recursion or an explicit stack. Kahn's is iterative and needs no recursion depth; DFS with visiting/visited states makes it easy to recover the cycle itself.
In an SDE II phone screen the interviewer asked this before the candidate started coding. Standard answer: in-degree counting with a queue (Kahn's algorithm, BFS), or DFS with visiting and visited sets (three colours) that detects a cycle when it reaches a course still on the current path; both are O(V + E).
One SDE II report gives this as the follow-up to the task-ordering question, without the answer. In the services version (which services are hit when some are taken down), an intern candidate started the affected set with the taken-down services, ran the in-degree queue, and added a service to the set whenever one of its dependencies was already in it. Standard answer: walk from the changed tasks along dependent edges to collect everything downstream, then return that set in topological order so each task comes after the ones it needs (Part 4).
In an SDE II phone screen this was the last ask, after time and space complexity. Standard answer: pick a small graph with a branch and a shared dependent, and trace the in-degrees, the queue and the output step by step.
Reported in phone screens (an SDE II screen of about 55 minutes that also had a system design discussion and a behavioral question; a package-install phone screen) and onsite coding rounds for interns, new grads, SDE II, L5, MLE and senior Applied Scientist candidates. In the SDE II screen the interviewer asked for other approaches before coding, asked whether the queue traversal was BFS or DFS (the report warns that calling it DFS draws repeated "Are you sure?"), asked for time and space complexity, then had the candidate walk a small example through the code. A new-grad candidate asked to validate a training-course catalog was asked about complexity and the difference between BFS and DFS. In the bar-raiser round of a five-round loop the follow-ups were a concrete order and then printing the courses on a cycle; the candidate described three-colour DFS but ran out of time to code it. An onsite build-order question required the DFS visiting/visited explanation and O(V + E) analysis. An intern candidate asked for an example; the interviewer had none prepared and drew a graph on the spot, and confirmed the input would have no cycle. An MLE candidate who wrote both the BFS and the DFS versions, and recalls needing no hints, was later told by HR that the feedback was that coding needed too many hints. An intern candidate whose round paired an OOD question with a Course Schedule II-like graph question spent a long time settling the OOD requirements, finished the code with almost no time left to explain it, and still passed.
Also reported as Course Schedule II · LeetCode 207
The round: 16 reports between October 2025 and September 2026, from intern, new-grad, SDE II, L5, MLE and senior Applied Scientist loops, in phone screens and onsite coding rounds. Most are LeetCode 207 and 210 (Course Schedule I and II), either as written or with an Amazon story on top: order tasks that have prerequisites, build a package after its dependencies, find the services hit when some go down. Several reports describe rounds that open with leadership-principle questions and leave the rest of the hour for code. One intern candidate notes that Amazon interviewers do not run the code, so explain the approach before writing it.
The page has four graded parts. Parts 2 to 4 are follow-ups reports describe after the base question.
Input (every part): prerequisites is a list of pairs [a, b] meaning b must be taken before a (LeetCode's convention). Courses (or tasks) are numbered 0 to n - 1. The tests use no repeated pairs and no course that is its own prerequisite.
Part 1 — can every course be finished?
def can_finish(num_courses: int, prerequisites: list) -> bool: ...
True if some order takes every course after all of its prerequisites, False if a cycle makes that impossible (LeetCode 207).Part 2 — return a valid order
def find_order(num_courses: int, prerequisites: list) -> list: ...
[] (LeetCode 210).Part 3 — print the courses on a cycle
def find_cycle(num_courses: int, prerequisites: list) -> list: ...
[] when there is no cycle.Part 4 — which tasks must rerun?
def tasks_to_rerun(num_tasks: int, prerequisites: list, changed: list) -> list: ...
changed have changed. Return every task that must rerun: the changed tasks plus every task that depends on one of them, directly or through other tasks. Order them so each task comes after the tasks it needs from that set. Any valid order is accepted. The task graph has no cycle.Reported variants (not graded)
install() that installs only itself; write installWithDependencies(package) so every dependency is installed first, and detect cyclic dependencies. In the same candidate's onsite, the question was the build order for one target package (it plus everything it needs) with a DFS that keeps a visiting set and a visited set. Not graded; the Solution has a sketch.Are there other ways to solve this?
Is your queue traversal BFS or DFS? Are you sure?
What are the time and space complexity?
Walk me through your code with a small example.
What is the difference between BFS and DFS here?
Can you return a concrete order, not just true or false?
If there is a cycle, can you print the courses on it?
Explain how the visiting and visited sets detect a cycle.
How do you handle cyclic dependencies?
If some tasks change, which tasks must rerun, including indirectly affected ones, and in what order?
Interviewer hints: In an SDE II phone screen the interviewer asked for other approaches before coding, then asked whether the queue traversal was BFS or DFS; the candidate warns that calling it DFS draws repeated "Are you sure?". The same interviewer asked for time and space complexity and a walk-through on a small example.; In the services-outage version the interviewer had no example prepared and drew a dependency graph when asked, confirmed the input would always be valid (no cycle), and let the candidate choose the input format.; In a package build-order onsite the candidate had to use DFS and explain the visiting set (current path) and the visited set (finished), with O(V + E) time and space.; In a bar-raiser round the follow-ups after LeetCode 207 were a concrete order, then printing the courses on a cycle.
Outcomes: An intern candidate who got a Course Schedule II-like question passed, though time spent settling an OOD question in the same round left almost none to explain the code. An MLE candidate who wrote both BFS and DFS was rejected; HR said the coding feedback was that it needed too many hints, which the candidate disputes. Another candidate who solved the course question onsite failed the loop; a reply in the thread puts it down to the behavioral answers.
Our note (standard advice, not from the reports): Say the edge direction out loud before coding: [a, b] means b comes before a, so the edge is b -> a.; Kahn's algorithm answers Parts 1 and 2 with one loop; a three-colour DFS is the natural tool once the cycle itself is wanted.; A DFS with a single seen set mistakes a diamond for a cycle.; Python's default recursion limit is about 1,000 frames, so prefer an explicit stack for long chains.
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 57 Amazon questions, refreshed monthly from new candidate reports.