Given an integer N, which is a power of 2, return a square of length N filled with the numbers {1, 2, 3, ... N2} followig the "Z Pattern".
This consists of recursively traversing the 4 quadrants in the order: upper-left, upper-right, lower-left, lower-right.
Example 1:
Input: N = 2
Output: [
[1, 2],
[3, 4]
]
Example 2:
Input: N = 4
Output:[
[1, 2, 5, 6],
[3, 4, 7, 8],
[9, 10, 13, 14]
[11, 12, 15, 16]
]
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check