Course Schedule Feasibility
Updated
Problem statement
You need to complete numCourses courses labeled from 0 to numCourses - 1.
Each pair [course, prerequisite] means that prerequisite must be completed before course.
Return true if it is possible to complete every course. Otherwise, return false.
Function
canFinishCourses(numCourses: int, prerequisites: int[][]) → booleanExamples
Example 1
numCourses = 2prerequisites = [[1,0]]return = trueTake course 0 first, then course 1.
Example 2
numCourses = 2prerequisites = [[1,0],[0,1]]return = falseEach course requires the other first, so the prerequisite graph contains a cycle.
Example 3
numCourses = 4prerequisites = [[1,0],[2,1],[3,2]]return = trueThe order 0, 1, 2, 3 completes every course.
Constraints
1 <= numCourses <= 2,000.0 <= prerequisites.length <= 5,000.- Every prerequisite pair contains two valid course labels.
- A course is never listed as its own prerequisite.
More Tesla Phone Screen questions
- Flatten a Branched List into a Doubly Linked ListPHONE SCREEN · Seen Sep 2026
- Reduce-Based Map and Filter PipelinePHONE SCREEN · Seen Sep 2026
- Resilient Fake API ClientPHONE SCREEN · Seen Sep 2026
- Merge JSON Array FieldsPHONE SCREEN · Seen Aug 2026
- KV Store with RollbackPHONE SCREEN · Seen Apr 2026
- Multi-Channel Valid ConvolutionPHONE SCREEN · Seen Oct 2024
- Average of a Fixed-Size ArrayPHONE SCREEN · Seen Jun 2024
- Swap Even and Odd BitsPHONE SCREEN · Seen Mar 2023
- Find the Intersection Node of Two Linked ListsPHONE SCREEN · Seen Oct 2022
- Priority, Expiration, and LRU EvictionPHONE SCREEN · Seen Mar 2021
Similar questions at other companies
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleNykaa · PHONE SCREEN
- Course ScheduleBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleOracle · ONSITE INTERVIEW
- Course SchedulePlaud · ONSITE INTERVIEW
- Course ScheduleFlexTrade · ONSITE INTERVIEW
- Can You Finish All Courses?Intuit · OA
- Can All Courses Be FinishedC3.ai · ONSITE INTERVIEW
- Trace Terminal Company OwnershipPalantir · ONSITE INTERVIEW
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN