You are given two Quad-Trees representing binary grids of size n ร n. Your mission is to perform a logical OR operation between these two grids and return the result as a new Quad-Tree.
What is a Quad-Tree?
A Quad-Tree is a tree data structure where each internal node has exactly four children representing quadrants: topLeft, topRight, bottomLeft, and bottomRight. Each node has two properties:
val: True if the region contains all 1's, False if all 0'sisLeaf: True if this node represents a uniform region (all same values)
The Challenge:
Given quadTree1 and quadTree2, return a Quad-Tree representing the bitwise OR of the two binary matrices. The OR operation follows these rules:
0 OR 0 = 00 OR 1 = 11 OR 0 = 11 OR 1 = 1
Think of it as overlaying two transparent sheets - wherever there's a 1 in either sheet, the result shows a 1!
Input & Output
Time & Space Complexity
Where n is the number of nodes in the larger tree, as we visit each node at most once
Recursion stack depth is at most logโ(grid_size) for balanced quad-trees
Constraints
- The number of nodes in both trees is in the range [1, 4h] where h is the height of the tree
- quadTree1 and quadTree2 represent n ร n grids
- n == 2x where 0 โค x โค 9
- The input trees are valid quad-trees