Decode a Binary Tree by Vertical Traversal
Problem statement
Each node value is the ASCII code of a lowercase letter. Give root column 0, left child column-1, and right child column+1. Read columns from smallest to largest; within a column read top-to-bottom, breaking same-row ties by left-to-right BFS discovery.
Concatenate the letters and return the decoded string.
Function
decodeVerticalTree(root: TreeNode) → StringExamples
Example 1
root = [114,101,116,null,null,101,null,99,null,115]return = "secret"Columns spell s, ec, re, t from left to right.
Constraints
- The tree contains at most
10^5nodes. - Values are ASCII codes 97 through 122.