Tap here to switch tabs
Problem
Submissions

Problem: Largest Magic Square

med
30 min
Try to solve the Largest Magic Square problem.

Statement

Given an m×nm \times n integer matrix grid, return the size of the largest magic square subgrid contained within grid.

A magic square is defined as a k×kk \times k subgrid where the sum of elements in every row, the sum of elements in every column, and the sum of elements along both diagonals are all equal. Note that any 1×11 \times 1 grid is always a magic square of size 11.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤m,n≤501 \leq m, n \leq 50

  • 1≤1 \leq grid[i][j] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Largest Magic Square

med
30 min
Try to solve the Largest Magic Square problem.

Statement

Given an m×nm \times n integer matrix grid, return the size of the largest magic square subgrid contained within grid.

A magic square is defined as a k×kk \times k subgrid where the sum of elements in every row, the sum of elements in every column, and the sum of elements along both diagonals are all equal. Note that any 1×11 \times 1 grid is always a magic square of size 11.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤m,n≤501 \leq m, n \leq 50

  • 1≤1 \leq grid[i][j] ≤106\leq 10^6