Tap here to switch tabs
Problem
Submissions

Problem: Magic Squares In Grid

Magic Squares In Grid asks you to count contiguous three-by-three subgrids in a matrix whose distinct values from one through nine give every row, column, and diagonal the same sum.

Statement

A 3×33 \times 3 magic square is a 3×33 \times 3 grid filled with distinct numbers from 11 to 99 such that every row, every column, and both diagonals share the same sum.

Given a row × col integer matrix grid, return the total number of contiguous 3×33 \times 3 magic square subgrids within grid.

Constraints:

  • row == grid.length

  • col == grid[i].length

  • 1≤1 \leq row, col ≤10\leq 10

  • 0≤0 \leq grid[i][j] ≤15\leq 15

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Magic Squares In Grid

Magic Squares In Grid asks you to count contiguous three-by-three subgrids in a matrix whose distinct values from one through nine give every row, column, and diagonal the same sum.

Statement

A 3×33 \times 3 magic square is a 3×33 \times 3 grid filled with distinct numbers from 11 to 99 such that every row, every column, and both diagonals share the same sum.

Given a row × col integer matrix grid, return the total number of contiguous 3×33 \times 3 magic square subgrids within grid.

Constraints:

  • row == grid.length

  • col == grid[i].length

  • 1≤1 \leq row, col ≤10\leq 10

  • 0≤0 \leq grid[i][j] ≤15\leq 15