FastPrepDecode a Binary Tree by Vertical Traversal

Decode a Binary Tree by Vertical Traversal

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

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) → String

Examples

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^5 nodes.
  • Values are ASCII codes 97 through 122.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String decodeVerticalTree(TreeNode root) {
  // Write your code here.
}
root[114,101,116,null,null,101,null,99,null,115]
expected"secret"
Checking account…