← Bloomberg Interview Insights

Bloomberg·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Bloomberg SWE interview with a tree traversal problem that looks straightforward until you actually try to implement it cleanly under pressure.

Questions Asked (1)

Q1

Given the root of a binary tree, return the vertical-order traversal of its node values, grouped by column from leftmost to rightmost, ordered top-to-bottom within each column, and sorted by level-order position when nodes share the same row and column.

Algorithms & Data Structures
Author's notes

The column tracking clicked pretty fast for me, root at zero, left minus one, right plus one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a BFS traversal to process nodes level by level, tracking each node's column index. Store nodes in a map keyed by column, and within each column, maintain a list of (row, value) pairs. After traversal, sort each column's list by row, then by value if rows are equal, and finally output columns from leftmost to rightmost.

Pro tip: Clarify the tie-breaking rule upfront: when multiple nodes share the same row and column, sort by their values. This shows attention to detail and avoids ambiguity during implementation.

1. Clarify the problem and edge cases

Confirm the tie-breaking rule (sort by value when row and column are equal) and discuss edge cases like empty tree, single node, or skewed tree.

2. Choose traversal and data structures

Use BFS with a queue to process nodes level by level, tracking each node's column index. Use a hash map to group nodes by column, storing (row, value) pairs.

3. Implement traversal and grouping

During BFS, for each node, append (row, value) to the list for its column. Enqueue left child with column-1 and right child with column+1.

4. Sort and output

Sort the columns by key (leftmost to rightmost). For each column, sort the list by row, then by value. Collect values in order and return.

Key Points to Mention

  • BFS ensures top-to-bottom order within each column.
  • Column index tracking: left child gets col-1, right child gets col+1.
  • Use a hash map (or TreeMap) to group nodes by column.
  • Sorting within columns: primary key row, secondary key value.
  • Time complexity: O(N log N) due to sorting, space O(N).
  • Edge cases: empty tree, nodes with same row and column.

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