Practice Construct Quad 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
Represent the n by n binary matrix grid with a quad tree and return its root. Each Node has boolean fields val and isLeaf, plus topLeft, topRight, bottomLeft, and bottomRight child pointers. If a region contains only one value, create a leaf whose val is that value (1 means true) and whose four children are null. Otherwise create a non-leaf, divide the region into four equal quadrants, and recursively build the corresponding children. A non-leaf may use either boolean value for val. The displayed output uses level-order serialization. Each node is [isLeaf, val], with booleans represented by 1 or 0; null marks an absent node.
Source: Construct Quad Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[0,1],[1,0]]
[[0,1],[1,0],[1,1],[1,1],[1,0]]
# Example 2
grid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]]
[[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]
Constraints
Related LeetCode Problems
Practice more problems similar to Construct Quad Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.