FastPrepTask Order with Dependencies
Problems/Task Order with Dependencies

Task Order with Dependencies

Notion logoNotion● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a Notion onsite interview loop for a software engineering role. The candidate said a coding round came down to topological sorting, and the interviewer then asked for the running-time complexity of the solution.

The account does not say what story or input the problem used, and gives no rule for ties or for dependencies that form a cycle. Here, the input is tasks with before-and-after pairs, the smallest ready task always goes next, and a cycle returns an empty array. The limits and examples are ours. The complexity follow-up is answered in the solution and is not tested.

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

Given n tasks labeled from 0 to n - 1 and an array dependencies, return the order in which the tasks are done, or an empty array if the dependencies form a cycle.

Each dependencies[i] = [a, b] means task a must be finished before task b can start. Tasks are done one at a time. A task is ready when every task it depends on is finished. Whenever more than one task is ready, you always do the ready task with the smallest label next.

In a cycle, tasks wait on each other, so none of them can ever become ready.

Function

findTaskOrder(n: int, dependencies: int[][]) → int[]

Examples

Example 1

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

Tasks 0, 3 and 4 depend on nothing, so they are ready at the start, and task 0 goes first. Task 1 still waits for task 3, so only tasks 3 and 4 are ready, and task 3 has the smaller label. Now tasks 1 and 4 are both ready, and task 1 has the smaller label, so it goes before task 4. Task 2 becomes ready only after tasks 1 and 4 are both done.

Example 2

n = 3dependencies = [[0,1],[1,2],[2,1]]return = []
dependencies
012

Task 0 can be done, but task 1 waits for task 2 and task 2 waits for task 1. Neither can ever start, so the answer is an empty array.

Example 3

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

No task depends on another, so all three are ready at once and are done from the smallest label up.

Constraints

  • 1 <= n <= 105
  • 0 <= dependencies.length <= 105
  • dependencies[i].length == 2
  • 0 <= a, b < n
  • a != b
  • All pairs [a, b] are distinct.

More Notion interview questions

  • Nested Todo ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Top Error Types in a Time WindowONSITE INTERVIEW · Seen Jun 2026
  • Text Document HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • DAG Downstream NodesONSITE INTERVIEW · Seen Apr 2026
  • Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
  • Page Permission InheritancePHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
  • Sliding Window MedianONSITE INTERVIEW · Seen Oct 2025
  • Task Row ModificationsONSITE INTERVIEW · Seen Oct 2025
  • JSON Block Tree OperationsONSITE INTERVIEW · Seen Jul 2025
  • Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026

Similar questions at other companies

  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Merge Subsequences Into a Consistent Total OrderGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Lexicographically Smallest Course OrderLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • ETL Pipeline SchedulerUnity · ONSITE INTERVIEW
  • Microservice Deployment OrderGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Course Schedule IIWalmart · ONSITE INTERVIEWWalmart interview questions
  • Task Order With PrerequisitesDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions

Interview reports that mention this question

  • Notion interviews · 2022

Notion interview experiences

  • Notion interviews · Before 2022
  • Notion interviews · 2023
  • Notion interviews · 2024
  • Notion interviews · 2025
  • Notion interviews · 2026
All Notion interview questionsSee Notion hiring insights
Saved
class Solution {
    public int[] findTaskOrder(int n, int[][] dependencies) {
      // Write your code here.
    }
}
Checking account…