FastPrepRoot Job with the Largest Total Duration
Problems/Root Job with the Largest Total Duration

Root Job with the Largest Total Duration

College Vine logoCollege Vine● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a College Vine phone screen. The report gives each job's own duration plus all of its descendants, valid job IDs, and picking the largest root. It leaves out ties and numeric limits. We chose those. Our version is about 95% the same as the reported question.

A job file describes one or more trees of jobs. The arrays ids, parentIds and durations have the same length. Entries at the same index describe one job. A parent of -1 represents the source file’s null root parent. Otherwise the parent is another job ID. IDs are unique and the relationships have no cycles.

A job’s total duration is its own duration plus the durations of all descendants. Return the ID of the root with the largest total. Add the duration of every descendant. You are counting all the work, not how much time the jobs would take when run together or along the longest path.

For this exercise, assume input records may arrive in any order, durations are nonnegative integer units, equal totals choose the smaller root ID, and an empty file returns -1. A job has at most fifteen direct children.

Further discussion

Explain how a min-heap of size three can retain the three largest root totals as a self-check. This discussion does not change the required result: return the root with the largest total, not the third largest.

Function

largestRootJob(ids: int[], parentIds: int[], durations: int[]) → int

Examples

Example 1

ids = [10,11,12,20]parentIds = [-1,10,10,-1]durations = [2,4,5,10]return = 10

Descendant sum beats single long root.

Example 2

ids = [7,2]parentIds = [-1,-1]durations = [5,5]return = 2

Tie chooses smaller root identity.

Example 3

ids = []parentIds = []durations = []return = -1

Empty job file.

Constraints

  • 0 <= ids.length = parentIds.length = durations.length <= 512.
  • IDs are distinct positive integers at most 10^9.
  • Each parent is -1 or another input ID; the input is an acyclic forest.
  • Every job has at most 15 direct children.
  • 0 <= durations[i] <= 10^6; totals fit a signed 32-bit integer.

More College Vine interview questions

  • Calculate a Token-List ExpressionONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Lowest Common Ancestor in an N-ary TreeGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Lowest Common Ancestor in an N-ary TreeAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
See College Vine hiring insights
Saved
class Solution {
    public int largestRootJob(int[] ids, int[] parentIds, int[] durations) {
        // Write your code here.
    }
}
Checking account…