Course Schedule
Reported by candidates from Kotak Mahindra Bank's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that matters in this Kotak Mahindra Bank question, reported in September 2026, is the line about returning false when the prerequisite graph contains a directed cycle. That's the whole problem. Course Schedule is cycle detection on a directed graph, dressed up as a scheduling story. If the assessment hands you this one, you either spot the cycle or you don't. Topological sort handles it cleanly, and DFS with three states works too. If you blank on the setup during the live OA, StealthCoder sits invisibly on your screen as a safety net and gives you the approach in real time.
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 it is possible to complete every course. Return false when the prerequisite graph contains 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,0],[3,1],[3,2]] return = true One valid completion order is 0, 1, 2, 3. Constraints 1 <= numCourses <= 2000 0 <= prerequisites.length <= 5000 Every prerequisite pair contains two distinct valid course labels. No prerequisite pair appears more than once.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build an adjacency list from the pairs, where [course, prerequisite] means an edge from prerequisite to course. Then use Kahn's algorithm. Compute 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 nodes, return true. Otherwise a cycle is blocking the rest, so return false. The DFS alternative needs three states: unvisited, visiting, done. Hitting a visiting node means a cycle. The common pitfall is flipping the edge direction, which still works for cycle detection but confuses your reasoning. Another is forgetting courses with no prerequisites, which have in-degree 0 and must start the queue. Complexity is O(V + E), well inside the 2000 and 5000 limits. If your mind goes blank mid-assessment, StealthCoder can surface this template so you just type it out.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
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 Kotak Mahindra Bank's OA.
Kotak Mahindra Bank reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Course Schedule FAQ
What's the trick to Course Schedule?+
Treat it as cycle detection in a directed graph. If a cycle exists, you can't finish every course. Use Kahn's topological sort and check whether you processed all numCourses nodes, or run DFS with visiting and done states.
Do I need to return the actual course order?+
No. This version only asks for a boolean. You return true if every course can be completed and false if the prerequisite graph has a directed cycle. Kahn's algorithm gives you an order for free, but you only need the count of processed nodes.
BFS or DFS, which is safer under pressure?+
Kahn's BFS is usually safer. It has no recursion, no three-state bookkeeping, and the cycle check is one comparison at the end: processed count versus numCourses. DFS is fine if you're comfortable with it, but the state marking is where people slip.
What edge cases should I test?+
Test empty prerequisites, which should return true. Test a two-node cycle like [[1,0],[0,1]], which returns false. Test a diamond shape like Example 3 to confirm shared dependencies don't trigger a false cycle. Also a disconnected graph, where some courses have no edges at all.
How do I prepare for this in 48 hours?+
Write Kahn's algorithm from memory twice, once in your OA language. Practice building the adjacency list and in-degree array without looking. Then try a DFS version. Graph cycle questions come up often, so that template pays off beyond this one problem.