Course Schedule II
Updated
Problem statement
Given numCourses courses labeled from 0 to numCourses - 1 and a list of prerequisites, return an order for taking every course. Each pair [course, prerequisite] means the prerequisite must be finished before the course.
If several orders work, return the lexicographically smallest one: at the first position where two orders differ, it has the smaller course number. If no order works, return an empty array.
Function
findCourseOrder(numCourses: int, prerequisites: int[][]) → int[]Examples
Example 1
numCourses = 2prerequisites = [[1,0]]return = [0,1]Course 0 must appear before course 1.
Example 2
numCourses = 4prerequisites = [[1,0],[2,0],[3,1],[3,2]]return = [0,1,2,3]After course 0, courses 1 and 2 are both available, so the smaller number, 1, goes next.
Example 3
numCourses = 2prerequisites = [[1,0],[0,1]]return = []The two courses form a cycle, so no complete ordering exists.
Constraints
1 <= numCourses <= 2000.0 <= prerequisites.length <= 5000.prerequisites[i].length == 2.0 <= course, prerequisite < numCourses.- Every prerequisite pair is unique, and a course is never its own prerequisite.
More Bloomberg LP Onsite Interview questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Find a Valid Course Completion OrderGoogle · ONSITE INTERVIEW
- Course Schedule IIWalmart · ONSITE INTERVIEW
- Task Order With PrerequisitesDoorDash · PHONE SCREEN · ONSITE INTERVIEW
- Course Schedule IIChainalysis · OA
- Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleOracle · ONSITE INTERVIEW
- Course SchedulePlaud · ONSITE INTERVIEW
- Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEW
- Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEW