Vertical Column Report of a Tree With Row and Value Tie-Breaking

Last updated: November 29, 2026

Quick Overview

Assign the root of a binary tree to row 0, column 0; a left child is at (row + 1, col - 1) and a right child at (row + 1, col + 1). Return node values column by column from left to right, within a column ordered by row, and by value when two nodes share a row and column.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Assign the root of a binary tree to row 0, column 0; a left child is at (row + 1, col - 1) and a right child at (row + 1, col + 1). Return node values column by column from left to right, within a column ordered by row, and by value when two nodes share a row and column.

A Google onsite question that looks like simple BFS but has strict ordering rules, similar to laying out a hierarchy on a Maps-style grid where overlapping markers need deterministic order. The interviewer checks that you notice BFS order alone does not satisfy the value tie-break.

What the Interviewer Expects
  • Record (col, row, val) for every node
  • Sort by column, then row, then value
  • Group consecutive entries by column
  • Explain why BFS order alone is insufficient for same-position ties
  • State O(n log n) time
Key Topics to Cover
binary trees
sorting
coordinate assignment
breadth-first search
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Can you avoid the full sort with per-column buckets?
  • Return only the top view (first node per column).
  • How would you render this incrementally as the tree grows?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: root. Output: list of columns from leftmost to rightmost; within each, values sorted by row ascending and, for equal rows, by value ascending. Empty tree returns []....

High-Level Design

Traverse the tree (any order) assigning coordinates and collect tuples (col, row, val). Sort them; Python's tuple ordering applies exactly the required priority. Then sweep the sorted list, starting...


Submit Your Answer
Markdown supported