Practice Largest Magic Square
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square. Given an m x n integer grid, return the size (i.e., the side length k) of the largest magic square that can be found within this grid.
Source: Largest Magic Square on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]
3
# Example 2
grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]]
2
Constraints
Related LeetCode Problems
Practice more problems similar to Largest Magic Square.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.