Decrypt a String from Binary Tree Columns
Updated
Problem statement
Given a binary tree stored in parallel arrays, return the decrypted string: the tree's letters read column by column. Every node holds one lowercase English letter.
values[i]is nodei's one-letter string.leftIndices[i]andrightIndices[i]are the indices of its left and right children, or-1when that child is missing.rootIndexis the root, or-1for an empty tree.
The root is in column 0. A left child is one column left of its parent, and a right child is one column right. Read the columns from leftmost to rightmost, and read each column from top to bottom. If two nodes share both row and column, take them in breadth-first order, which reads each row from left to right.
Function
decryptTreeColumns(values: String[], leftIndices: int[], rightIndices: int[], rootIndex: int) → StringExamples
Example 1
values = ["i","r","e","p","c"]leftIndices = [1,3,4,-1,-1]rightIndices = [2,-1,-1,-1,-1]rootIndex = 0return = "price"The columns are [p], [r], [i,c], and [e]. Node c is the left child of e, so it shares the root's column.
Example 2
values = ["a","b","c","d","e","f","g"]leftIndices = [1,3,5,-1,-1,-1,-1]rightIndices = [2,4,6,-1,-1,-1,-1]rootIndex = 0return = "dbaefcg"Nodes e and f share a row and a column. A breadth-first walk reaches e first, so e comes before f.
Example 3
values = []leftIndices = []rightIndices = []rootIndex = -1return = ""An empty tree decrypts to the empty string.
Constraints
0 <= values.length <= 100000.- The three arrays have equal length.
- Every
values[i]contains exactly one lowercase English letter. - Every child index is
-1or a valid array index. - When nonempty, the arrays describe one valid rooted binary tree and every node is reachable exactly once from
rootIndex. rootIndex == -1exactly when the arrays are empty.
More Bloomberg LP Phone Screen questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Flat Records to a Hierarchical TreeAddepar · PHONE SCREEN
- Flat Comments to a Nested TreeByteDance · PHONE SCREENByteDance interview questions
- Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Predicate Expression Tree EvaluatorMongoDB · PHONE SCREENMongoDB interview questions
- Render a Stable Comment HierarchyBobyard · PHONE SCREEN
- Transform and Prune a Mode-Valued Binary TreeGoogle · PHONE SCREENGoogle interview questions
- Everyone Under a ManagerAdobe · PHONE SCREENAdobe interview questions
- Team Cost Under a ManagerRippling · PHONE SCREENRippling interview questions