PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/BlackRock

Traverse a tree and answer 2D prefix sums

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competency in tree traversal and array preprocessing, specifically in-order traversal of binary trees and 2D prefix-sum techniques for answering submatrix-sum queries.

  • easy
  • BlackRock
  • Coding & Algorithms
  • Software Engineer

Traverse a tree and answer 2D prefix sums

Company: BlackRock

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given two independent coding tasks. ## Task 1: In-order traversal of a binary tree Given the root of a binary tree, return the in-order traversal of its node values. - **In-order** means: traverse left subtree → visit node → traverse right subtree. - **Input:** `root` (may be `null`) - **Output:** an array/list of node values in in-order - **Constraints (typical):** up to ~10^5 nodes; values fit in 32-bit int. ## Task 2: Sum of the top-left submatrix up to (x, y) Given an `m x n` matrix `A` of integers and coordinates `(x, y)` (0-indexed), compute the sum of all elements in the rectangle from `(0,0)` to `(x,y)` inclusive. Example: `sum(x,y) = Σ_{i=0..x} Σ_{j=0..y} A[i][j]` - **Input:** matrix `A`, and one or more queries `(x, y)` where `0 ≤ x < m`, `0 ≤ y < n` - **Output:** for each query, return the computed sum - **Follow-up (common):** If there are many queries, design for fast per-query time. - **Constraints (typical):** `m,n` up to ~10^3 or higher; values can be negative; sums may require 64-bit integer type.

Quick Answer: This question evaluates a candidate's competency in tree traversal and array preprocessing, specifically in-order traversal of binary trees and 2D prefix-sum techniques for answering submatrix-sum queries.

Related Interview Questions

  • Solve two interval array problems - BlackRock (medium)
  • Design paint editor with undo/redo - BlackRock (easy)
  • Implement sorting and set intersection with input parsing - BlackRock (Medium)
  • Solve hierarchy distance and digit-square convergence - BlackRock (Medium)
BlackRock logo
BlackRock
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

You are given two independent coding tasks.

Task 1: In-order traversal of a binary tree

Given the root of a binary tree, return the in-order traversal of its node values.

  • In-order means: traverse left subtree → visit node → traverse right subtree.
  • Input: root (may be null )
  • Output: an array/list of node values in in-order
  • Constraints (typical): up to ~10^5 nodes; values fit in 32-bit int.

Task 2: Sum of the top-left submatrix up to (x, y)

Given an m x n matrix A of integers and coordinates (x, y) (0-indexed), compute the sum of all elements in the rectangle from (0,0) to (x,y) inclusive.

Example: sum(x,y) = Σ_{i=0..x} Σ_{j=0..y} A[i][j]

  • Input: matrix A , and one or more queries (x, y) where 0 ≤ x < m , 0 ≤ y < n
  • Output: for each query, return the computed sum
  • Follow-up (common): If there are many queries, design for fast per-query time.
  • Constraints (typical): m,n up to ~10^3 or higher; values can be negative; sums may require 64-bit integer type.

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.