PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Bloomberg

Find tree root and bucket numbers

Last updated: Mar 29, 2026

Quick Overview

This two-part question evaluates understanding of tree data representations and interval bucketing, testing competencies in identifying a tree root from parent–child adjacency records and in classifying numeric values into sorted-interval buckets; it falls within the data structures and algorithms domain (tree structures and array/interval processing). It is commonly used to assess reasoning about data invariants and edge-case handling — with the implicit assumptions that node ids are unique (no duplicates), inputs may be empty, boundaries may be negative, and values outside the outermost boundaries are treated as out of range — and it emphasizes a mix of conceptual understanding and practical algorithmic application.

  • hard
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Find tree root and bucket numbers

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given two independent tasks. ## Task 1: Find the root of a tree from adjacency logs You are given an unordered list of records describing a rooted tree. Each record is: - `node`: a node id (string or integer) - `children`: a list of node ids that are direct children of `node` All node ids are unique. Each node (except the root) appears as a child of exactly one other node. The root never appears as any node’s child. **Goal:** Return the id of the root node. **Input example:** - `[(1, [2, 3]), (2, [4]), (3, []), (4, [])]` **Output example:** - `1` ## Task 2: Bucket values between boundaries You are given: - A sorted array of numeric boundaries `B` of length `m` where `B[i] < B[i+1]` - An array of numeric values `A` Define buckets (intervals) between consecutive boundaries: - Bucket `i` corresponds to the interval `[B[i], B[i+1])` for `i = 0 .. m-2` Values `< B[0]` and `>= B[m-1]` are considered out of range. **Goal:** Classify values in `A` into these buckets and return an array `counts` of length `m-1`, where `counts[i]` is the number of values that fall into bucket `i`. **Example:** - `B = [0, 10, 20, 50]` - `A = [-1, 0, 3, 10, 19, 20, 49, 50]` Buckets: - `[0,10)`: values `{0,3}` → count 2 - `[10,20)`: values `{10,19}` → count 2 - `[20,50)`: values `{20,49}` → count 2 Output: - `[2, 2, 2]` State any assumptions you make about duplicates, empty inputs, and whether boundaries can be negative.

Quick Answer: This two-part question evaluates understanding of tree data representations and interval bucketing, testing competencies in identifying a tree root from parent–child adjacency records and in classifying numeric values into sorted-interval buckets; it falls within the data structures and algorithms domain (tree structures and array/interval processing). It is commonly used to assess reasoning about data invariants and edge-case handling — with the implicit assumptions that node ids are unique (no duplicates), inputs may be empty, boundaries may be negative, and values outside the outermost boundaries are treated as out of range — and it emphasizes a mix of conceptual understanding and practical algorithmic application.

Related Interview Questions

  • Solve meeting and tree problems - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)
  • Solve common string/tree/grid interview tasks - Bloomberg (medium)
Bloomberg logo
Bloomberg
Mar 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

You are given two independent tasks.

Task 1: Find the root of a tree from adjacency logs

You are given an unordered list of records describing a rooted tree. Each record is:

  • node : a node id (string or integer)
  • children : a list of node ids that are direct children of node

All node ids are unique. Each node (except the root) appears as a child of exactly one other node. The root never appears as any node’s child.

Goal: Return the id of the root node.

Input example:

  • [(1, [2, 3]), (2, [4]), (3, []), (4, [])]

Output example:

  • 1

Task 2: Bucket values between boundaries

You are given:

  • A sorted array of numeric boundaries B of length m where B[i] < B[i+1]
  • An array of numeric values A

Define buckets (intervals) between consecutive boundaries:

  • Bucket i corresponds to the interval [B[i], B[i+1]) for i = 0 .. m-2

Values < B[0] and >= B[m-1] are considered out of range.

Goal: Classify values in A into these buckets and return an array counts of length m-1, where counts[i] is the number of values that fall into bucket i.

Example:

  • B = [0, 10, 20, 50]
  • A = [-1, 0, 3, 10, 19, 20, 49, 50]

Buckets:

  • [0,10) : values {0,3} → count 2
  • [10,20) : values {10,19} → count 2
  • [20,50) : values {20,49} → count 2

Output:

  • [2, 2, 2]

State any assumptions you make about duplicates, empty inputs, and whether boundaries can be negative.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Bloomberg•More Software Engineer•Bloomberg Software Engineer•Bloomberg Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.