Back to problems

Construct Quad Tree

Algorithm · Uber · Medium

You receive an n x n binary array named grid, with n guaranteed to be a power of two. Create and return the root node of the quad tree encoding this array. A node corresponds to one square portion of the grid: A region containing only one repeated value becomes a leaf node. A mixed region becomes an internal node that has four children: top-left, top-right, bottom-left, and bottom-right. Each node in the result must provide val, isLeaf, topLeft, topRight, bottomLeft, and…

Checking your access…