Practice Print Binary Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Create a string matrix showing the given binary tree. If its height measured in edges is h, use h + 1 rows and 2^(h + 1) - 1 columns, initially filled with empty strings. Put the root in the middle column of row 0. For a node at row r and column c, place its left child at row r + 1, column c - 2^(h - r - 1), and its right child at row r + 1, column c + 2^(h - r - 1). Store each node's value as a string and return the completed matrix.
Source: Print Binary Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [1,2]
[["","1",""], ["2","",""]]
# Example 2
root = [1,2,3,null,4]
[["","","","1","","",""], ["","2","","","","3",""], ["","","4","","","",""]]
Constraints
Related LeetCode Problems
Practice more problems similar to Print Binary Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.