Skip to content

Practice Fill a Special Grid

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

Medium#3537
LeetCode Problem

Fill a Special Grid

Problem Statement

Given n, fill a 2^n by 2^n grid with the integers 0 through 2^(2 * n) - 1, each once. Every number in the top-right quadrant must be smaller than every number in the bottom-right quadrant; bottom-right values must all be smaller than bottom-left values; and bottom-left values must all be smaller than top-left values. Each quadrant must recursively satisfy the same rules. A 1 by 1 grid is special. Return the resulting special grid.

Source: Fill a Special Grid on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 0
Output
[[0]]

# Example 2

Input
n = 1
Output
[[3,0],[2,1]]

# Example 3

Input
n = 2
Output
[[15,12,3,0],[14,13,2,1],[11,8,7,4],[10,9,6,5]]

Constraints

0 <= n <= 10

Related LeetCode Problems

Practice more problems similar to Fill a Special Grid.

Review your practice with PhantomCodeAI

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