Meta Interview Problem #6 — Vertical Order Traversal (Left-to-Right Columns)

Problem (English original):
Given the root of a binary tree containing integers, return a list of all the integers in the tree ordered by column from left to right. Within each column, values should be ordered from top to bottom.

Assume a node definition (or language equivalent):

struct Node {
  Node *left;
  Node *right;
  int val;
};

Input (example, ASCII tree):

      6
     / \
    3   4
   / \ / \
  5  1 7  0
   \    /
    2  8
   / \
  9   7

Output (example):

[5, 9, 3, 2, 6, 1, 7, 4, 8, 0]

Summary (approach):
BFS/DFS tagging each node with (col,row) (root at col=0). Group values by col, then sort columns left→right and, within each column, sort by row top→bottom. Concatenate results. Time O(n log n), space O(n).

The VOprep team has long accompanied candidates through various major company OAs and VOs, including OpenAI, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0