Biggest Square
You are given an n x m grid representing a plot of land.
Each cell contains either a 1 (usable land) or a 0 (unusable rock).
Your goal is to find the biggest square area of usable land (a square containing only 1s) and return its total area.
Example 1:
Input: grid = [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]
Output: 4
Explanation:
We need to find the largest square containing only '1's. The largest such square has side length = 2.
Example square:
1 1
1 1
Since the side length is 2, the area of the square is:
2 × 2 = 4
There are actually two possible 2×2 squares in this matrix,
but the maximum area remains 4.
Example 2:
Input: grid = [[0,1],[1,0]]
Output: 1
Explanation:
All '1's are isolated. No 2×2 square of '1's exists.
The largest possible square is a single cell containing '1'.
Now Your Turn!
Pick the correct output for the given inputInput: grid = [[1,1,1,1],[1,1,1,0],[1,1,1,1],[0,1,1,1]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n, m <= 300
- grid[i][j] is either 0 or 1.