FastPrepFind Root of N-Ary Tree
Problems/Find Root of N-Ary Tree

Find Root of N-Ary Tree

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg new grad phone screen. The report names a well-known problem but leaves out its statement, examples, and limits. We added those. Our version is about 88% the same as the reported question.

An N-ary tree has one node for every distinct integer in values. Each pair [parent, child] in edges is a directed tree edge from a node to one of its children.

The edges form exactly one valid rooted tree over all labels in values. Return the label of its root.

Function

findRoot(values: int[], edges: int[][]) → int

Examples

Example 1

values = [1,2,3,4,5,6]edges = [[1,3],[1,2],[1,4],[3,5],[3,6]]return = 1

Every label except 1 appears as a child, so 1 is the root.

Example 2

values = [7]edges = []return = 7

A one-node tree has no edges, and its only label is the root.

Example 3

values = [5,1,9,4]edges = [[9,5],[9,1],[1,4]]return = 9

The child labels are 5, 1, and 4. The remaining label 9 is the root.

Constraints

  • 1 <= values.length <= 100000.
  • All labels in values are distinct integers between -10^9 and 10^9.
  • edges.length == values.length - 1.
  • Every edge contains two labels from values.
  • Every non-root label appears exactly once as a child, and the edges form one valid N-ary tree.

More Bloomberg LP Phone Screen questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Flat Records to a Hierarchical TreeAddepar · PHONE SCREEN
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Flat Comments to a Nested TreeByteDance · PHONE SCREENByteDance interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Predicate Expression Tree EvaluatorMongoDB · PHONE SCREENMongoDB interview questions
  • Render a Stable Comment HierarchyBobyard · PHONE SCREEN
  • Delete Selected Nodes from a Parent-Array ForestSnowflake · PHONE SCREENSnowflake interview questions
  • Construct a Tree from Level-Order and Inorder TraversalsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Find Nodes with Invalid Parent LevelsZip · ONSITE INTERVIEWZip interview questions
  • Validate BST Node DescriptionsAirbnb · OAAirbnb interview questions

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int findRoot(int[] values, int[][] edges) {
        // Write your code here.
    }

}
Checking account…