Reported December 2020
Bloombergbreadth first search

Decode a Binary Tree by Vertical Traversal

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The trap in this Bloomberg OA, reported December 2020, is the tie-break rule. Two nodes can share the same column and the same row, and if you walk the tree with plain DFS, they come out in the wrong order. It's a vertical order traversal on a binary tree with up to 10^5 nodes, and the output is a decoded string. The pattern is tree plus BFS plus a column map. It looks easy until the same-row ordering bites you. If you blank on the tiebreak logic during the live OA, StealthCoder is the safety net running invisibly on your screen.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Run a BFS from the root with a queue of (node, column) pairs. Store each letter in a hash map keyed by column, appending in the order BFS discovers it. Since BFS goes level by level and left before right, top-to-bottom and left-to-right ties fall out for free. Track the min and max column as you go, then loop from min to max and concatenate. That avoids sorting keys. The pitfall is DFS. Recursive DFS visits a deep left node before a shallow right one in the same column, which breaks the row ordering unless you sort by row. Recursion on 10^5 nodes can also overflow the stack on a skewed tree. Convert values with chr(). If the tie rule or the column bookkeeping slips away mid-assessment, StealthCoder can hand you the BFS version in real time. Complexity is O(n) time and space.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Decode a Binary Tree by Vertical Traversal cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as binary tree vertical order traversal. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Decode a Binary Tree by Vertical Traversal FAQ

What's the trick in the Bloomberg vertical traversal decode problem?+

Use BFS, not DFS. BFS visits nodes level by level and left to right, so the tie-break rule is satisfied automatically. Keep a map from column to a list of letters, then read columns from min to max. No sorting needed.

How hard is this problem really?+

It's medium. The idea is simple once you see BFS plus a column map. The difficulty is the ordering rule for same-row, same-column nodes, and a DFS attempt that quietly gets it wrong on certain trees.

Why does DFS fail here?+

DFS can reach a deeper node in a column before a shallower one, so the append order is wrong. You'd have to store row numbers and sort each column. BFS avoids that entirely, and it also dodges recursion depth limits on 10^5-node skewed trees.

Do I need to sort the column keys?+

No. Track the minimum and maximum column while traversing, then iterate from min to max. That keeps the whole solution linear instead of adding an n log n sort on the keys.

How do I prepare for this in 48 hours?+

Write the BFS vertical order solution from scratch twice. Test it on a skewed tree, a single node, and a tree where two nodes share a row and column. Practice the min/max column loop and the chr() conversion so the final assembly is automatic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it