FastPrepCourse Schedule II
Problems/Course Schedule II

Course Schedule II

Chainalysis logoChainalysis● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Chainalysis new grad online assessment report describes Course Schedule II with a rule that ties go to the smallest in dictionary order. Our version is about 99% the same as the reported question.

You are given numCourses courses labeled from 0 to numCourses - 1 and a list of prerequisite pairs. Each pair [course, prerequisite] means that prerequisite must be completed before course.

Return an order in which all courses can be completed. Whenever several courses have no remaining prerequisites, choose the smallest numbered course next. If the prerequisite graph contains a cycle and completing every course is impossible, return an empty array.

Function

findOrder(numCourses: int, prerequisites: int[][]) → int[]

Examples

Example 1

numCourses = 2prerequisites = [[1, 0]]return = [0, 1]

Course 0 has no prerequisite. Completing it unlocks course 1.

Example 2

numCourses = 4prerequisites = [[1, 0], [2, 0], [3, 1], [3, 2]]return = [0, 1, 2, 3]

After course 0, both courses 1 and 2 are available. The smaller course is chosen first.

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
  • Each prerequisite pair contains two distinct course labels in the range [0, numCourses - 1].
  • All prerequisite pairs are unique.
  • When multiple courses are available, choose the smallest course label first.

More Chainalysis interview questions

  • Longest Common SuffixOA · Seen Nov 2022
  • Meeting RoomsPHONE SCREEN · Seen Apr 2025
  • Meeting Rooms IIPHONE SCREEN · Seen Apr 2025
  • Block Transaction Count TrendsONSITE INTERVIEW · Seen Mar 2025
  • Filter Team A LogsONSITE INTERVIEW · Seen Mar 2025
  • Filter Team A Transfer LogsONSITE INTERVIEW · Seen Mar 2025
  • High-Severity Counts by Search TypeONSITE INTERVIEW · Seen Mar 2025
  • Team A High-Severity Transfer HashesONSITE INTERVIEW · Seen Mar 2025

Similar questions at other companies

  • Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Find a Valid Course Completion OrderGoogle · ONSITE INTERVIEWGoogle interview questions
  • Course Schedule IIWalmart · ONSITE INTERVIEWWalmart interview questions
  • Task Order With PrerequisitesDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Course Schedule IIBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Distances to CyclesBelvedere Trading · OA
  • Maximum Safeness of a Grid PathIntuit · OAIntuit interview questions
  • Course ScheduleInMobi · OAInMobi interview questions
  • Course Order, Lowest Number FirstNutanix · OANutanix interview questions
  • Satellite Network Message PropagationOptiver · OAOptiver interview questions
All Chainalysis interview questionsSee Chainalysis hiring insights
Saved
class Solution {
    public int[] findOrder(int numCourses, int[][] prerequisites) {
      // write your code here
    }
}
Checking account…