Fill a Special Grid
You are given a non-negative integer n representing a 2^n x 2^n grid. You must fill the grid with integers from 0 to 2^(2n) - 1 to make it special.
A grid is special if it satisfies all the following conditions:
- All numbers in the top-right quadrant are smaller than those in the bottom-right quadrant.
- All numbers in the bottom-right quadrant are smaller than those in the bottom-left quadrant.
- All numbers in the bottom-left quadrant are smaller than those in the top-left quadrant.
- Each of its quadrants is also a special grid.
Return the special 2^n x 2^n grid.
Note: Any 1 x 1 grid is special.
Example 1
Input
n = 0Output
[[0]]The only number that can be placed is 0, and there is only one possible position in the grid.
Example 2
Input
n = 1Output
[[3,0],[2,1]]The quadrants contain top-right 0, bottom-right 1, bottom-left 2, and top-left 3, so
0 < 1 < 2 < 3 satisfies the constraints.Constraints
- 0 <= n <= 10