Course Schedule
Reported by candidates from FlexTrade's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole problem hinges on one data structure: an adjacency list, and a directed graph hiding behind a course list. FlexTrade reported Course Schedule in January 2026, and it's the classic cycle detection question dressed up as prerequisites. If the assessment hands you numCourses and a pile of [course, prerequisite] pairs, you're being asked one thing: does this directed graph contain a cycle. You've probably seen the shape before. The risk isn't the idea, it's blanking on the details under a timer. StealthCoder sits invisibly on your screen as a safety net if that happens, but you can walk in knowing the script.
The problem
There are numCourses courses labeled from 0 through numCourses - 1. Each pair [course, prerequisite] means that prerequisite must be completed before course. Return true if all courses can be completed. Return false if the prerequisite relationships contain a directed cycle. Function canFinish(numCourses: int, prerequisites: int[][]) → boolean Examples Example 1 numCourses = 2 prerequisites = [[1,0]] return = true Course 0 can be completed before course 1. Example 2 numCourses = 2 prerequisites = [[1,0],[0,1]] return = false Each course requires the other first, so the graph contains a cycle. Example 3 numCourses = 4 prerequisites = [[1,0],[2,1],[3,2]] return = true The courses can be completed in the order 0, 1, 2, 3. Constraints 1 <= numCourses <= 2000 0 <= prerequisites.length <= 5000 Every pair contains two valid course labels from 0 through numCourses - 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build an adjacency list from the pairs, with an edge from prerequisite to course. Then pick a cycle detection method. The cleanest is Kahn's algorithm, a BFS topological sort. Count in-degrees, push every course with in-degree 0 into a queue, pop one, decrement its neighbors, and push any that hit 0. If you process all numCourses, return true. Otherwise a cycle blocked some courses, so return false. The DFS alternative uses three states per node: unvisited, visiting, done. Hitting a visiting node means a cycle. The common pitfall is using a plain visited set, which flags diamond shapes as cycles. Another is forgetting that courses with no prerequisites still count. Constraints are small, up to 2000 courses and 5000 edges, so O(V+E) is easily fast enough. If your mind goes blank mid-assessment, StealthCoder can surface the full solution so you don't lose the round over syntax.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
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. If you're reading this with an OA window open, you're who this was built for.
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 FlexTrade's OA.
FlexTrade reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Course Schedule FAQ
What's the trick in Course Schedule?+
Treat it as a directed graph and check for a cycle. If any cycle exists, you can't finish all courses. Topological sort via in-degrees (Kahn's algorithm) is the easiest way to detect it without recursion bugs.
How hard is Course Schedule really?+
Medium, but it's one of the most standard graph questions. Once you recognize it as cycle detection, the code is about 20 lines. The difficulty is recognizing the graph and handling the edge direction correctly.
Should I use BFS or DFS for this?+
Either works. BFS with in-degrees is harder to get wrong, since there's no recursion state to manage. DFS needs three node states, not just visited and unvisited. Pick whichever you can write from memory without hesitating.
What mistakes fail test cases most often?+
Reversing edge direction is harmless for cycle detection, but mixing it up inside one solution isn't. Other killers are using a two-state visited set in DFS, and ignoring courses that appear in no pair. Also handle an empty prerequisites array, which returns true.
How do I prepare in 48 hours?+
Write Kahn's algorithm from scratch twice without looking. Then write the DFS version once. Test on the cycle example [[1,0],[0,1]] and the chain example. Then glance at related topological sort variants like returning the actual course order.