FastPrepCourse Schedule II
Problems/Course Schedule II

Course Schedule II

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names Course Schedule II and follows it with validation, complexity, testing, and a nested-list output. The parallel-round judged core matches the visible source at about 85%.

There are numCourses courses labeled from 0 to numCourses - 1. Each pair [course, prerequisite] means the prerequisite must be completed before the course.

Return a nested list of parallel study rounds. Each round contains every course whose prerequisites were completed in earlier rounds, sorted in ascending order. If no valid schedule includes every course, return an empty outer array.

Function

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

Examples

Example 1

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

Course 0 is available first. Completing it unlocks course 1 for the next round.

Example 2

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

After course 0, courses 1 and 2 can be completed together; both unlock course 3.

Example 3

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

The two courses form a cycle, so no schedule can include every course.

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.
  • Each course appears in exactly one returned round, and values inside a round are ascending.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] findCourseOrder(int numCourses, int[][] prerequisites) {
      // write your code here
    }
}
Checking account…