Traverse Tree Columns with Stable Row Ties

Quick Overview

Traverse Tree Columns with Stable Row Ties. Return node values column by column from left to right, and top to bottom within each column. The root has column zero; left and right children shift by -1 and

Traverse Tree Columns with Stable Row Ties

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return node values column by column from left to right, and top to bottom within each column. The root has column zero; left and right children shift by -1 and +1. For nodes sharing row and column, preserve their left-to-right tree order, not sorted value order. Keep the TreeNode* root API. ```cpp vector<vector<int>> verticalOrder(TreeNode* root); ``` ### Examples ```text root = [8,4,12,2,7,6,14] -> [[2],[4],[8,7,6],[12],[14]] root = [] -> [] ``` ### Constraints - There are 0 through 100 nodes. - Values lie in [-100,100].

Overview: Traverse Tree Columns with Stable Row Ties. Return node values column by column from left to right, and top to bottom within each column. The root has column zero; left and right children shift by -1 and

Bloomberg logo
Bloomberg
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return node values column by column from left to right, and top to bottom within each column. The root has column zero; left and right children shift by -1 and +1. For nodes sharing row and column, preserve their left-to-right tree order, not sorted value order. Keep the TreeNode* root API.

vector<vector<int>> verticalOrder(TreeNode* root);

Examples

root = [8,4,12,2,7,6,14] -> [[2],[4],[8,7,6],[12],[14]]
root = [] -> []

Constraints

  • There are 0 through 100 nodes.
  • Values lie in [-100,100].