DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Tree

Vertical Order Traversal

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Vertical Order Traversal** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** BFS with (col, row) tuples; sort by col then row **Edge Cases to Consider:** - (1) Single node - (2) All left children (all different cols) - (3) Nodes with same col and row

Examples

Example 1
Input: [3,9,20,null,null,15,7]
Output: [[9],[3,15],[20],[7]]
Explanation: Classic
Example 2
Input: [1,2,3,4,5,6,7]
Output: [[4],[2],[1,5,6],[3],[7]]
Explanation: Full 3-level
Example 3
Input: [1]
Output: [[1]]
Explanation: Single node

Constraints

  • ▪The number of nodes in the tree is in the range [0, 2000]
  • ▪-1000 <= Node.val <= 1000
  • ▪Ensure depth-first or breadth-first traversals are memory-efficient

Watch Out For Edge Cases

  • ▪Single node
  • ▪All left children (all different cols)
  • ▪Nodes with same col and row
Frequently Asked At
MetaAmazonGoogleAdobe