PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/BlackRock

Solve hierarchy distance and digit-square convergence

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of tree and graph modeling, shortest-path reasoning, iterative function behavior and cycle detection, along with time and space complexity analysis within the Coding & Algorithms domain.

  • Medium
  • BlackRock
  • Coding & Algorithms
  • Software Engineer

Solve hierarchy distance and digit-square convergence

Company: BlackRock

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

You have two independent tasks: A) Organization hierarchy distance Given a list of (employee, manager) pairs that form a complete hierarchy (a single connected tree), and a query with two employee names, compute the number of reporting levels between the two employees. If the employees are the same person, return 0. The two people may be in different branches (no direct managerial line). Input format: first line contains the two names to compare; subsequent lines contain space-separated employee manager pairs covering the entire company. Output a single integer equal to the number of edges on the shortest path between the two employees in the hierarchy. Describe your approach (e.g., build an undirected graph and run BFS, or compute depths and use LCA), and analyze time and space complexity. B) Digit-square convergence check Define f(n) as the sum of the squares of the decimal digits of n. Repeatedly apply f starting from a positive integer n. Implement a function that returns true if the sequence reaches 1, and false if it falls into a cycle that does not include 1. Provide two solutions: one using extra memory (e.g., a set of seen values) and one using O( 1) space via cycle detection (e.g., Floyd’s tortoise–hare). State the time and space complexities.

Quick Answer: This question evaluates understanding of tree and graph modeling, shortest-path reasoning, iterative function behavior and cycle detection, along with time and space complexity analysis within the Coding & Algorithms domain.

Related Interview Questions

  • Solve two interval array problems - BlackRock (medium)
  • Traverse a tree and answer 2D prefix sums - BlackRock (easy)
  • Design paint editor with undo/redo - BlackRock (easy)
  • Implement sorting and set intersection with input parsing - BlackRock (Medium)
BlackRock logo
BlackRock
Sep 6, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
1
0

You have two independent tasks:

A) Organization hierarchy distance Given a list of (employee, manager) pairs that form a complete hierarchy (a single connected tree), and a query with two employee names, compute the number of reporting levels between the two employees. If the employees are the same person, return 0. The two people may be in different branches (no direct managerial line). Input format: first line contains the two names to compare; subsequent lines contain space-separated employee manager pairs covering the entire company. Output a single integer equal to the number of edges on the shortest path between the two employees in the hierarchy. Describe your approach (e.g., build an undirected graph and run BFS, or compute depths and use LCA), and analyze time and space complexity.

B) Digit-square convergence check Define f(n) as the sum of the squares of the decimal digits of n. Repeatedly apply f starting from a positive integer n. Implement a function that returns true if the sequence reaches 1, and false if it falls into a cycle that does not include 1. Provide two solutions: one using extra memory (e.g., a set of seen values) and one using O(

  1. space via cycle detection (e.g., Floyd’s tortoise–hare). State the time and space complexities.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More BlackRock•More Software Engineer•BlackRock Software Engineer•BlackRock 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.