FastPrepCourse Order, Lowest Number First
Problems/Course Order, Lowest Number First

Course Order, Lowest Number First

Nutanix logoNutanix● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A fall-2018 report from a Nutanix intern online assessment asks for a course order. A tie rule favors lower course numbers. The report calls the task a variant of the classic course-prerequisite exercise.

The report gives no input format, limits or examples. It does not say what to return when no order exists. Here courses are numbered 0 to n - 1, and a pair [a, b] means a comes before b. "Lower-numbered first" means the order that is smaller when compared position by position. An empty list is returned when no order exists. n is 1 to 2000 with up to 10^4 distinct pairs. The examples are ours.

Our version is about 75% the same as the reported question.

There are n courses numbered from 0 to n - 1. Each pair prerequisites[i] = [a, b] means course a must be taken before course b.

Return an order in which all n courses can be taken, one at a time, so that every course comes after all of its prerequisites. If several orders are possible, return the one that takes lower-numbered courses first: compared position by position, it has the smaller course number at the first position where two orders differ.

If no order is possible, return an empty list.

Function

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

Examples

Example 1

n = 5prerequisites = [[3,1],[0,1],[4,2]]return = [0,3,1,4,2]

Course 1 needs courses 3 and 0 first, and course 2 needs course 4 first. At the start, courses 0, 3 and 4 have no prerequisites. Take the smallest, 0. Then take 3, which makes course 1 ready (both of its prerequisites are done). Now 1 and 4 are ready, so take 1, then 4, which makes 2 ready, and finally 2. The order is [0, 3, 1, 4, 2]. Other orders such as [0, 3, 4, 1, 2] are also valid, but at the third position they have 4 where this one has the smaller 1.

Example 2

n = 3prerequisites = [[0,1],[1,2],[2,0]]return = []

Course 0 must come before 1, 1 before 2, and 2 before 0. That is a cycle, so no order exists and the answer is an empty list.

Example 3

n = 3prerequisites = []return = [0,1,2]

There are no prerequisites, so every order is valid. The one that takes lower-numbered courses first is [0, 1, 2].

Constraints

  • 1 <= n <= 2000
  • 0 <= prerequisites.length <= 10^4
  • prerequisites[i].length == 2
  • 0 <= prerequisites[i][0], prerequisites[i][1] < n
  • prerequisites[i][0] != prerequisites[i][1]
  • All pairs in prerequisites are distinct.

More Nutanix Online Assessment questions

  • Good SubsequencesOA · Seen Jul 2026
  • Min Cost to Connect All PointsOA · Seen Jun 2026
  • Digit Changes for a Multiple of 9OA · Seen Aug 2025
  • Gas Station Loop StartOA · Seen Aug 2025
  • Number of Players (for MTS2)OA · Seen Oct 2024
  • Work Schedules (for MTS2)OA · Seen Oct 2024
  • Minimum Operations to Convert ArrayOA · Seen Apr 2024
  • No Adjacent CharactersOA · Seen Apr 2024
  • Build a BST From a ListOA · Seen Nov 2022
  • Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022

Similar questions at other companies

  • Course Schedule IIChainalysis · OAChainalysis interview questions
  • Lexicographically Smallest Topological OrderIntuit · OAIntuit interview questions
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Dependency-Aware Task SchedulerRippling · PHONE SCREENRippling interview questions
  • Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Merge Subsequences Into a Consistent Total OrderGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Lexicographic Dependency OrderIllumio · PHONE SCREENIllumio interview questions
  • Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Lexicographically Smallest Course OrderLinkedIn · ONSITE INTERVIEWLinkedIn interview questions

Interview reports that mention this question

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)

Nutanix interview experiences

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public int[] findCourseOrder(int n, int[][] prerequisites) {
        // Write your code here.
    }
}
Checking account…