A 3 x 3 magic square is a 3 x 3 grid filled with the distinct numbers 1 to 9 such that every row, every column and both diagonals have the same sum. Given a row x col grid of integers, count how many contiguous 3 x 3 subgrids are magic squares. The grid itself may contain numbers up to 15.
A 3 x 3 magic square is a 3 x 3 grid filled with the distinct numbers 1 to 9 such that every row, every column and both diagonals have the same sum. Given a row x col grid of integers, count how many contiguous 3 x 3 subgrids are magic squares. The grid itself may contain numbers up to 15.
Example 1:
Input: {"grid":[[4,3,8,4],[9,5,1,9],[2,7,6,2]]}
Output: 1
Constraints:
row=grid.length
col=grid[i].length
1≤row,col≤10
0≤grid[i][j]≤15
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"grid":[[4,3,8,4],[9,5,1,9],[2,7,6,2]]}
A 3 x 4 grid has 2 possible 3 x 3 windows. Slide one over every position.