Skip to content

Practice Logical OR of Two Binary Grids Represented as Quad-Trees

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#558
LeetCode Problem

Logical OR of Two Binary Grids Represented as Quad-Trees

Problem Statement

Return a quad tree representing the cell-by-cell logical OR of the two n by n binary grids. Each node has val, isLeaf and four children: topLeft, topRight, bottomLeft and bottomRight. A uniform region is a leaf whose val is that region's common value and whose children are null. A mixed region is a non-leaf with four recursively constructed quadrant children; its val may be either boolean value. The serialized level-order form uses [isLeaf, val], with 1 for true and 0 for false; null represents a missing node.

Source: Logical OR of Two Binary Grids Represented as Quad-Trees on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
quadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]] , quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]
Output
[[0,0],[1,1],[1,1],[1,1],[1,0]]

# Example 2

Input
quadTree1 = [[1,0]], quadTree2 = [[1,0]]
Output
[[1,0]]

Constraints

quadTree1 and quadTree2 are both valid Quad-Trees each representing a n * n grid.
n == 2^x where 0 <= x <= 9.

Related LeetCode Problems

Practice more problems similar to Logical OR of Two Binary Grids Represented as Quad-Trees.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.