Course Schedule Feasibility
Updated
Problem statement
There are numCourses courses labeled from 0 through numCourses - 1. Each pair [course, prerequisite] means the prerequisite must be completed before that course. Return true if every course can be completed in some order, or false if the dependencies contain a cycle.
Courses without prerequisites may be taken at any time. The result asks only whether a complete order exists; do not return the order itself.
Function
canFinishCourses(numCourses: int, prerequisites: int[][]) → booleanExamples
Example 1
numCourses = 2prerequisites = [[1,0]]return = trueTake course 0 before course 1.
Example 2
numCourses = 2prerequisites = [[1,0],[0,1]]return = falseEach course requires the other first, so neither can be completed.
Example 3
numCourses = 3prerequisites = [[1,0],[2,1]]return = trueThe dependency chain 0 → 1 → 2 completes all three courses.
Constraints
1 <= numCourses <= 20000 <= prerequisites.length <= 5000- Each prerequisite pair has exactly two course indices in
[0, numCourses - 1]. - Prerequisite pairs are unique. A self-dependency is a cycle.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Add Course Batches All or NothingAmazon · ONSITE INTERVIEW
- Course ScheduleByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
- Package Install OrderVerily · ONSITE INTERVIEW
- Course SchedulePlaud · ONSITE INTERVIEW
- Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Lexicographically Smallest Course OrderLinkedIn · ONSITE INTERVIEWLinkedIn interview questions