0840. Magic Squares In Grid
https://leetcode.com/problems/magic-squares-in-grid
Description
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.
Given a row x col grid of integers, how many 3 x 3 "magic square" subgrids are there? (Each subgrid is contiguous).
Example 1:

Example 2:
Example 3:
Example 4:
Constraints:
row == grid.lengthcol == grid[i].length1 <= row, col <= 100 <= grid[i][j] <= 15
ac
Last updated
Was this helpful?