FastPrepEarliest Dependency Schedule
Problems/Earliest Dependency Schedule

Earliest Dependency Schedule

Headlands Technologies logoHeadlands Technologies● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a 75-minute online assessment to design a job scheduler, but gives no job model, protocol, or examples. This exercise assumes a valid dependency graph with no cycles, positive durations, unlimited workers, and an output of the earliest start and finish. The array interface, the order, and the limits are our choice. Our version is about 45% the same as the available report.

There are N jobs with indices from 0 through N - 1. Job i takes durations[i] units of time. Each dependency [before, after] means that job after can start only when job before has finished.

The dependency graph is acyclic. All jobs are available at time 0, and there are unlimited workers, so independent jobs may run simultaneously. Start every job as early as its dependencies allow.

Return one array that lists each job’s start time followed by its finish time, in job-index order: [start[0], finish[0], start[1], finish[1], ...]. A job with no prerequisites starts at 0. Any other job starts at the latest finish time among all its direct prerequisites; its finish time is its start time plus its duration.

If there are no jobs, return an empty array. The input is valid; no error output for cycles or invalid indices is required.

Function

earliestSchedule(durations: int[], dependencies: int[][]) → long[]

Examples

Example 1

durations = [3,2,4,1]dependencies = [[0,2],[1,2],[2,3]]return = [0,3,0,2,3,7,7,8]

Jobs 0 and 1 start at time 0. Job 2 waits until both finish, at time 3; job 3 starts when job 2 finishes at time 7.

Example 2

durations = []dependencies = []return = []

There are no jobs, so the schedule has no start or finish values.

Example 3

durations = [5,7,11]dependencies = [[2,1],[1,0]]return = [18,23,11,18,0,11]

Job 2 runs first from time 0 to 11, followed by job 1 and then job 0. Return pairs in job-index order, rather than execution order.

Constraints

  • 0 <= N <= 10^5.
  • 0 <= dependencies.length <= 2 * 10^5.
  • 1 <= durations[i] <= 10^9.
  • Each dependency has exactly two valid job indices, no self-edge or duplicate edge occurs, and the directed graph is acyclic.
  • When N = 0, the dependency list is empty.
  • Return times as signed 64-bit integers. A path duration is at most 10^14.

More Headlands Technologies interview questions

  • Disaster RecoveryOA · Seen Nov 2026
  • Array Interval SumsOA · Seen Oct 2026
  • Job Runner Chain ReportsOA · Seen Oct 2026
  • Minimum Changes for Distinct Adjacent CharactersOA · Seen Sep 2026
  • Sliding-Window Means with IEEE Special ValuesOA · Seen Sep 2026
  • As-Of JoinOA · ONSITE INTERVIEW · Seen Aug 2026
  • Exclusive Function Execution TimesOA · Seen Jan 2024
  • Integer Compression OffsetPHONE SCREEN · Seen Oct 2026
  • Market Order BookPHONE SCREEN · Seen Jun 2026
  • Gradient Descent on a Sinusoidal ObjectivePHONE SCREEN · Seen Apr 2026

Similar questions at other companies

  • Distances to CyclesBelvedere Trading · OA
  • Detect a Cycle in Directed Hate RelationshipsArcesium · OAArcesium interview questions
  • Course Schedule IIChainalysis · OAChainalysis interview questions
  • Can You Finish All Courses?Intuit · OAIntuit interview questions
  • Module Rebuild CostsAirbnb · OAAirbnb interview questions
  • Course ScheduleInMobi · OAInMobi interview questions
  • Course Order, Lowest Number FirstNutanix · OANutanix interview questions
  • Validate a Directed GraphShopify · OAShopify interview questions
  • Print ScheduleOptiver · OAOptiver interview questions
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
All Headlands Technologies interview questionsSee Headlands Technologies hiring insights
Saved
class Solution {
    public long[] earliestSchedule(int[] durations, int[][] dependencies) {
        // write your code here
    }
}
Checking account…