FastPrepRoot of the Largest Tree
Problems/Root of the Largest Tree

Root of the Largest Tree

Goldman Sachs logoGoldman Sachs● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports give the rule that ties go to the smallest root, and a limit of at most 100,000 edges. They do not give a runnable function signature or examples. This version uses parallel arrays of parents and children. Our version is about 94% the same as the reported question.

You are given parallel integer arrays parents and children describing a forest of rooted trees. For every index i, parents[i] is the direct parent of children[i].

The nodes are exactly the distinct IDs that appear in either array. The associations form a valid acyclic forest, and every child appears at most once. A node that never appears in children is the root of its tree.

The size of a tree is its number of distinct nodes. Return the root ID of a tree with maximum size. If several trees have the same maximum size, return the smallest root ID.

Function

findLargestTreeRoot(parents: int[], children: int[]) → int

Examples

Example 1

parents = [1,1,2,10]children = [2,3,4,11]return = 1

The tree rooted at 1 contains nodes {1,2,3,4}. The tree rooted at 10 contains {10,11}, so return 1.

Example 2

parents = [5,8,8,9]children = [6,9,10,11]return = 8

The tree rooted at 8 contains 8,9,10,11, while the other tree contains only 5,6.

Constraints

  • 1 <= parents.length = children.length <= 100000.
  • -10^9 <= parents[i], children[i] <= 10^9.
  • The associations form a valid acyclic forest.
  • Every child ID appears at most once, and parents[i] != children[i].

More Goldman Sachs Phone Screen questions

  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Hash MapOA · PHONE SCREEN · Seen Nov 2026
  • House Robber IIIPHONE SCREEN · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
  • Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
  • Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Count Staircase WaysPHONE SCREEN · Seen Oct 2026
  • Is a Power of TenPHONE SCREEN · Seen Oct 2026
  • Minimum Traveling Salesperson TourPHONE SCREEN · Seen Oct 2026
  • Square Root with Newton IterationPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Package Install OrderVerily · ONSITE INTERVIEW
  • Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
  • Find the Unique User with Access to Every CameraVerkada · PHONE SCREENVerkada interview questions
  • Validate and Resolve Evaluation ChainsPlaid · PHONE SCREEN · ONSITE INTERVIEWPlaid interview questions
  • Page Referrer ReachabilityAmazon · ONSITE INTERVIEW
  • Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
  • Unique Transitive Dependent CountsRobinhood · PHONE SCREENRobinhood interview questions
  • Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int findLargestTreeRoot(int[] parents, int[] children) {
      // write your code here
    }
}
Checking account…