Reported October 2026
ByteDancegraph

Course Schedule

Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ByteDance OA. Under 2s to a working solution.
Founder's read

The pairs look like [course, prerequisite], and the whole question is whether that directed graph has a cycle. ByteDance reported this Course Schedule OA in October 2026, and it's the classic cycle detection problem dressed up as scheduling. If you've seen topological sort, you're fine. If your mind goes blank on the edge direction, you lose ten minutes. StealthCoder is the safety net running invisibly during the live OA if you freeze, but the pattern is simple enough to lock in tonight.

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 prerequisite to course. Then run 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. Count how many courses you pop. If the count equals numCourses, return true. Otherwise a cycle is blocking the rest, so return false. The alternative is DFS with three states: unvisited, visiting, done. Hitting a visiting node means a cycle. The common pitfall is reversing the edge direction, which still works for cycle detection but confuses your debugging. Another is forgetting courses with no edges, which Kahn's handles naturally. Constraints are 2000 courses and 5000 edges, so O(V+E) is trivial. If you blank during the live ByteDance OA, StealthCoder can surface the queue-based solution while you keep typing like normal.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as course schedule. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass ByteDance's OA.

ByteDance reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Course Schedule FAQ

How hard is the ByteDance Course Schedule question really?+

It's a medium that feels easy once you recognize it. The whole task is detecting a directed cycle. With 2000 courses and 5000 edges, a linear graph traversal passes easily. The risk is only in not recognizing the pattern or botching the edge setup.

What's the trick to solve Course Schedule?+

Treat it as cycle detection in a directed graph. Use Kahn's algorithm with in-degrees and a queue. If you process every course, no cycle exists. If fewer than numCourses get processed, a cycle blocks the rest and you return false.

Should I use DFS or BFS for this?+

Either works. BFS with in-degrees (Kahn's) is easier to write without recursion bugs. DFS needs three states, not just a visited flag, or you'll false-flag shared prerequisites as cycles. Pick the one you can write from memory without hesitating.

Does the pair order [course, prerequisite] matter?+

Yes for building the graph. The pair [a, b] means b comes before a, so add an edge from b to a and increment a's in-degree. Flipping it still detects cycles correctly, but mixing directions mid-code gives wrong in-degrees and wrong answers.

How do I prepare for this in 48 hours?+

Write Kahn's algorithm from scratch twice, then write the DFS version once. Test it on the three examples, especially the two-node cycle. Then try a variant that returns the actual order. That covers most graph questions an OA like this would throw at you.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ByteDance.

OA at ByteDance?
Invisible during screen share
Get it