3537. Fill a Special Grid Medium

@problem@discussion
#Array#Divide and Conquer#Matrix



1/**
2 * [3537] Fill a Special Grid
3 *
4 * You are given a non-negative integer <font face="monospace">n</font> 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:
5 * 
6 * 	All numbers in the top-right quadrant are smaller than those in the bottom-right quadrant.
7 * 	All numbers in the bottom-right quadrant are smaller than those in the bottom-left quadrant.
8 * 	All numbers in the bottom-left quadrant are smaller than those in the top-left quadrant.
9 * 	Each of its quadrants is also a special grid.
10 * 
11 * Return the special 2^n x 2^n grid.
12 * Note: Any 1x1 grid is special.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">n = 0</span>
17 * Output: <span class="example-io">[[0]]</span>
18 * Explanation:
19 * The only number that can be placed is 0, and there is only one possible position in the grid.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">n = 1</span>
24 * Output: <span class="example-io">[[3,0],[2,1]]</span>
25 * Explanation:
26 * The numbers in each quadrant are:
27 * 
28 * 	Top-right: 0
29 * 	Bottom-right: 1
30 * 	Bottom-left: 2
31 * 	Top-left: 3
32 * 
33 * Since 0 < 1 < 2 < 3, this satisfies the given constraints.
34 * </div>
35 * <strong class="example">Example 3:
36 * <div class="example-block">
37 * Input: <span class="example-io">n = 2</span>
38 * Output: <span class="example-io">[[15,12,3,0],[14,13,2,1],[11,8,7,4],[10,9,6,5]]</span>
39 * Explanation:
40 * <img alt="" src="https://assets.leetcode.com/uploads/2025/03/05/4123example3p1drawio.png" style="width: 161px; height: 161px;" />
41 * The numbers in each quadrant are:
42 * 
43 * 	Top-right: 3, 0, 2, 1
44 * 	Bottom-right: 7, 4, 6, 5
45 * 	Bottom-left: 11, 8, 10, 9
46 * 	Top-left: 15, 12, 14, 13
47 * 	max(3, 0, 2, 1) < min(7, 4, 6, 5)
48 * 	max(7, 4, 6, 5) < min(11, 8, 10, 9)
49 * 	max(11, 8, 10, 9) < min(15, 12, 14, 13)
50 * 
51 * This satisfies the first three requirements. Additionally, each quadrant is also a special grid. Thus, this is a special grid.
52 * </div>
53 *  
54 * Constraints:
55 * 
56 * 	0 <= n <= 10
57 * 
58 */
59pub struct Solution {}
60
61// problem: https://leetcode.com/problems/fill-a-special-grid/
62// discuss: https://leetcode.com/problems/fill-a-special-grid/discuss/?currentPage=1&orderBy=most_votes&query=
63
64// submission codes start here
65
66impl Solution {
67    pub fn special_grid(n: i32) -> Vec<Vec<i32>> {
68        vec![]
69    }
70}
71
72// submission codes end
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77
78    #[test]
79    fn test_3537() {
80    }
81}
82

Back
© 2026 bowen.ge All Rights Reserved.