Given an n x n matrix grid of 0's and 1's (n is a power of two), build its Quad-Tree representation. A Quad-Tree node has a boolean val (the region's value) and a boolean isLeaf (true if the node represents a region of all the same value). A leaf's val is the common cell value; an internal node has exactly four children — topLeft, topRight, bottomLeft, bottomRight — each covering one quadrant. Build the tree recursively: if a region is uniform it becomes a leaf, otherwise split it into four equal quadrants. This catalog task returns the tree serialized in level order as a list of [isLeaf, val] pairs (1/0), where every internal node is followed by its four children.
Example 1
Input: grid = [[0,1],[1,0]]
Output: [[0,1],[1,0],[1,1],[1,1],[1,0]]
Explanation: The 2x2 grid mixes 0s and 1s, so the root is an internal node ([0,1]). It splits into four 1x1 quadrants: top-left 0, top-right 1, bottom-left 1 and bottom-right 0. Each is a leaf: [1,0], [1,1], [1,1], [1,0].
Example 2
Input: grid = [[1,1],[1,1]]
Output: [[1,1]]
Explanation: Every cell is 1, so the whole grid is one uniform region and collapses into a single leaf with value 1: [[1,1]].
Example 3
Input: grid = [[0,0],[0,0]]
Output: [[1,0]]
Explanation: Every cell is 0, so the whole grid is one leaf with value 0: [[1,0]].
A quadrant is either uniform — in which case one leaf describes it exactly — or it is mixed, in which case the only way to describe it is to split it into its four equal sub-quadrants and describe each recursively. That 'uniform → leaf, else split into four' rule is the entire construction, applied top-down.
Run checks all cases above. Submit evaluates all test cases.