Course Schedule
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole Amazon Course Schedule question hinges on one data structure: a directed graph, stored as an adjacency list. Reported in September 2026, it asks if you can finish every course given [course, prerequisite] pairs. Translation: does this graph have a cycle? If you see the graph, you're 80% done. If you blank on how to detect the cycle under pressure, StealthCoder runs invisibly during the live OA and gives you a working solution as a safety net. Amazon also reportedly threw follow-ups about alternative solutions, edge cases, and complexity, so know two approaches, not one.
The problem
There are numCourses courses labeled from 0 to numCourses - 1. Each pair [course, prerequisite] means the prerequisite must be completed before the course. Return true if all courses can be completed, or false if the prerequisite graph contains a cycle. Interview Follow-up The interviewer asked follow-up questions about alternative solutions, edge cases, and complexity analysis. Function canFinish(numCourses: int, prerequisites: int[][]) → boolean Examples Example 1 numCourses = 2 prerequisites = [[1,0]] return = true Example 2 numCourses = 2 prerequisites = [[1,0],[0,1]] return = false Each course requires the other first, creating a cycle.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build an adjacency list from the prerequisites, then detect a cycle. Two clean ways. First, Kahn's algorithm: compute in-degrees, push every course with in-degree 0 into a queue, pop and decrement neighbors, and count how many you process. If the count equals numCourses, return true. Second, DFS with three states: unvisited, visiting, visited. Hitting a visiting node means a cycle. The common pitfall is using a plain visited set, which flags diamond shapes as cycles when they aren't. Another is flipping the edge direction, though for a pure cycle check it doesn't matter. Watch for empty prerequisites and disconnected components, since you must start from every node. Complexity is O(V + E) time and space. If you freeze mid-assessment, StealthCoder is the hedge that reads the problem and hands you the code.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Course Schedule cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as course schedule. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Course Schedule FAQ
How hard is Course Schedule really?+
It's a medium, and it's mostly recognition. Once you see prerequisites as directed edges and the question as cycle detection, the code is about 20 lines. The difficulty is choosing between BFS and DFS and not botching the cycle states.
What's the trick to Amazon's Course Schedule?+
Model it as a directed graph and check for a cycle. Topological sort via in-degree counting is the easiest to get right. If every course gets processed, there's no cycle and the answer is true.
Should I use BFS or DFS?+
Either works with O(V + E) time. Kahn's BFS is harder to mess up because there's no recursion state to track. DFS needs three-color marking. Since follow-ups ask for alternatives, be ready to explain both briefly.
What edge cases should I check?+
Empty prerequisites list, a single course, self-loops like [0,0], duplicate pairs, and disconnected components. Make sure your loop starts from every node, not just node 0, or you'll miss cycles in separate parts of the graph.
How do I prepare in 48 hours?+
Write Kahn's algorithm from memory twice, then the DFS version once. Trace both examples by hand. Practice stating time and space complexity out loud, since Amazon reportedly asked about complexity and alternatives as follow-ups.