Can You Finish All Courses?
Updated
Problem statement
There are numCourses courses, numbered from 0 through numCourses-1. Each row [course, prerequisite] in prerequisites means the prerequisite must be completed before that course.
Return true if all courses can be completed, and false otherwise. A course may require several prerequisites, and every one of them must be completed first. Courses absent from the pair list still exist and have no listed prerequisites.
A directed cycle, including a self-prerequisite, makes completion impossible. Return only the feasibility decision, not a course order.
Function
canFinish(numCourses: int, prerequisites: int[][]) → booleanExamples
Example 1
numCourses = 2prerequisites = [[1,0]]return = trueComplete course 0 first and then course 1. That order satisfies the only prerequisite, so both courses can be completed.
Example 2
numCourses = 2prerequisites = [[1,0],[0,1]]return = falseCourse 1 waits for course 0, and course 0 waits for course 1. Neither can start, so completing all courses is impossible.
Constraints
1 <= numCourses <= 2000.0 <= prerequisites.length <= 5000.- Every prerequisite row contains exactly two integers, each from 0 through numCourses-1.
- All prerequisite pairs are unique.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Course SchedulePlaud · ONSITE INTERVIEW
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleNykaa · PHONE SCREENNykaa interview questions
- Course ScheduleFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Course ScheduleBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Course Schedule FeasibilityTesla · PHONE SCREENTesla interview questions
- Can All Courses Be FinishedC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Trace Terminal Company OwnershipPalantir · ONSITE INTERVIEWPalantir interview questions
- Distances to CyclesBelvedere Trading · OA
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions