← BlackRock Interview Insights

BlackRock·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

BlackRock software engineer interview with two coding problems back to back. One graph/tree problem and one number theory thing. Nothing behavioral, just straight into the code.

Questions Asked (2)

Q1

Given a list of employee-manager pairs forming a company hierarchy tree, and two employee names, find the number of edges on the shortest path between them in the tree.

Algorithms & Data StructuresSystem Design
Author's notes

My first instinct was to compute depths and find the lowest common ancestor, which works but I fumbled explaining the LCA part clearly under pressure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the hierarchy as an undirected tree, then find the shortest path between the two employees. Use LCA (Lowest Common Ancestor) to compute the distance as depth(a) + depth(b) - 2*depth(lca). Alternatively, BFS from one employee to the other works but is less efficient for repeated queries.

Pro tip: Clarify whether the hierarchy is guaranteed to be a tree (single root, no cycles) and whether the two employees are always in the same tree. Mention that if the tree is large and queries are frequent, precomputing depths and binary lifting for LCA gives O(log n) per query.

1. Clarify input and assumptions

Confirm that the pairs form a valid tree (one root, no cycles) and that both employees exist. Ask if the tree is static or dynamic, and if multiple queries will be made.

2. Build the tree representation

Construct an adjacency list from the manager-employee pairs, treating edges as undirected. Identify the root (the employee with no manager) if needed.

3. Choose an algorithm

For a single query, BFS from one employee to the other is simple and O(n). For multiple queries, preprocess for LCA (e.g., binary lifting) to answer in O(log n) per query.

4. Compute distance

If using LCA, compute depths of both nodes and their LCA, then distance = depth(a) + depth(b) - 2*depth(lca). If using BFS, track distance during traversal.

5. Analyze complexity and edge cases

Discuss time/space complexity. Handle edge cases: same employee (distance 0), one is ancestor of the other, or disconnected (if not guaranteed tree).

Key Points to Mention

  • Tree representation: adjacency list from manager-employee pairs, undirected edges.
  • BFS for single query: O(n) time, O(n) space, simple to implement.
  • LCA with binary lifting: O(n log n) preprocessing, O(log n) per query, efficient for multiple queries.
  • Distance formula: dist(a,b) = depth(a) + depth(b) - 2*depth(lca).
  • Edge cases: same employee, ancestor-descendant relationship, disconnected nodes.
  • Complexity trade-offs: BFS vs. LCA preprocessing based on number of queries.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Implement a function that checks whether repeatedly applying 'sum of squares of digits' to a number eventually reaches 1. Provide a solution using a seen-values set and a second solution using O(1) space cycle detection.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The set-based version was easy, just track visited numbers and bail if you see a repeat that isn't 1.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then present the two required solutions: one using a hash set to detect cycles, and another using Floyd's cycle detection algorithm for O(1) space. Compare their time and space complexities, and discuss when each is preferable.

Pro tip: Mention that the sum of squares operation always leads to a cycle, and the only cycle that reaches 1 is the happy number cycle; all other cycles never include 1. This shows deep understanding and can help justify the cycle detection approach.

1. Understand and clarify the problem

Restate the problem: given a positive integer, repeatedly replace it with the sum of the squares of its digits, and determine if it eventually becomes 1. Ask about constraints (e.g., input size, negative numbers) and confirm that the process always enters a cycle.

2. Design the seen-values set solution

Use a hash set to store numbers encountered. At each step, compute the sum of squares of digits; if it's 1, return true; if it's already in the set, return false; otherwise add it and continue. Analyze time complexity: O(log n) per step, but number of steps is bounded by a constant for 32-bit integers.

3. Design the O(1) space cycle detection solution

Apply Floyd's tortoise and hare algorithm: use two pointers, slow and fast, where slow advances one step and fast advances two steps. If they meet, a cycle exists; if fast reaches 1, return true. This uses constant extra space.

4. Compare trade-offs and discuss edge cases

Compare the two solutions: the set approach is simpler but uses O(k) space where k is the cycle length or path length; Floyd's uses O(1) space but may do more computations. Discuss edge cases: input 1 (immediately happy), input 0 (not positive, but if allowed, 0 leads to 0 cycle), and large numbers.

5. Conclude with recommendation

Summarize that both solutions are valid; the set approach is easier to implement and understand, while Floyd's is more space-efficient. In an interview, mention that for 32-bit integers, the maximum sum of squares is bounded (e.g., 9^2 * 10 = 810), so the set size is small, making the set approach practically O(1) space as well.

Key Points to Mention

  • Definition of a happy number and the cycle property: all numbers eventually enter a cycle, and the only cycle containing 1 is the trivial one.
  • Time complexity: each step takes O(log n) to compute sum of squares, but the number of steps is bounded by a constant for fixed integer size.
  • Space complexity: hash set uses O(k) where k is the number of distinct numbers before a cycle; Floyd's uses O(1).
  • Floyd's cycle detection algorithm (tortoise and hare) and how it applies to this problem.
  • Edge cases: input 1, input 0 (if allowed), and negative numbers (if not specified, assume positive).
  • Practical optimization: precompute sum of squares for digits 0-9 to speed up computation.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.