Skip to content

Commit e1aa16c

Browse files
Update 221 - Maximal Square.md
1 parent 7b833f3 commit e1aa16c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

dsa-solutions/lc-solutions/0200-0299/221 - Maximal Square.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: Maximal Square
2+
id: maximal-square
33
title: Maximal Square
44
sidebar_label: 221 Maximal Square
55
tags:
@@ -12,7 +12,7 @@ description: "This document provides a solution where we find the largest square
1212

1313
## Problem
1414

15-
You are given an m x n binary $matrix$ filled with $0's$ and $1's$, find the largest square containing only $1's$ and return its area.
15+
You are given an m x n binary $matrix$ filled with 0's and 1's, find the largest square containing only 1's and return its area.
1616

1717
### Examples
1818

@@ -43,7 +43,7 @@ You are given an m x n binary $matrix$ filled with $0's$ and $1's$, find the lar
4343
- $m == matrix.length$
4444
- $n == matrix[i].length$
4545
- $1 <= m, n <= 300$
46-
- $matrix[i][j]$ $is$ $'0'$ $or$ $'1'$
46+
- $matrix[i][j]$ is $0$ or $1$
4747

4848
---
4949
## Approach
@@ -56,7 +56,7 @@ There are four approaches discussed that helps to obtain the solution:
5656

5757
2. **Transition**:
5858

59-
- If **'matrix[i][j]'** is $'1'$:
59+
- If **'matrix[i][j]'** is $1$:
6060
- If **'i'** or **'j'** is $0$ (first row or first column), **'dp[i][j]'** is $1$ because the largest square ending there can only be of $size1$.
6161

6262
- Otherwise, **'dp[i][j]'** is the minimum of **'dp[i-1][j]'**, **'dp[i][j-1]'**, and **'dp[i-1][j-1]'** plus $1$. This is because we can form a larger square only if all three adjacent squares can also form squares of $1's$.
@@ -119,7 +119,7 @@ class Solution {
119119

120120
> **Reason**: The algorithm involves iterating through each cell of the matrix once, leading to a time complexity of $𝑂(𝑚 × 𝑛)$, where $𝑚$ is the number of rows and $𝑛$ is the number of columns.
121121
122-
#### Space Complexity: O($m$ × $n2$)
122+
#### Space Complexity: O($m$ × $n$)
123123

124124
> **Reason**: The space complexity is $𝑂(𝑚 × 𝑛)$ due to the additional DP array used. This could be optimized to $O(n)$ by reusing a single row of DP values, but in the given solution, we use a full 2D DP array.
125125

0 commit comments

Comments
 (0)