Maximal square | Dynamic programming | Leetcode #221 | Largest Square Submatrix of all 1's

Maximal square | Dynamic programming | Leetcode #221 | Largest Square Submatrix of all 1's

Code with Alisha

2 года назад

19,680 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@BereniceVirginis
@BereniceVirginis - 05.02.2024 17:16

Space Complexity: O(1)

int maxSquare(int n, int m, vector<vector<int>> mat){
// code here
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
ans=max(ans,mat[i][j]);
}
if(ans==1)
{
break;
}
}
for(int i=1;i<n;i++)
{
for(int j=1;j<m;j++)
{ if(mat[i][j]==1){
int x=min(min(mat[i-1][j],mat[i][j-1]),mat[i-1][j-1]);
ans=max(ans,x+1);
mat[i][j]=x+1;
}
}
}
return ans;
}

Ответить
@Shivam-wl7fg
@Shivam-wl7fg - 14.01.2024 19:25

Nice Explanation 😃

Ответить
@govinth2462
@govinth2462 - 06.12.2023 15:36

I mam I want talk with your about my features opportunity where can connect with you

Ответить
@ankk98
@ankk98 - 26.11.2023 14:38

The intuition behind this algo is that we are checking for all possible squares ending at the given index.
So, we are using the results of maximum sized squares ending at 3 adjacent indexes and using that information to find out the max possible solution at current index.

Ответить
@user-bb8os4rw5i
@user-bb8os4rw5i - 27.03.2023 16:55

thankyou so much worth watching!!!!

Ответить
@raj_kundalia
@raj_kundalia - 16.03.2023 17:47

thank you!

Ответить
@tiger7858
@tiger7858 - 20.01.2023 04:03

inside if( i = = 0 || j = = 0) you are doing unnecessary work you can leave it as it is , nice explanation overall 🙏thank you

Ответить
@Coding_Destini
@Coding_Destini - 31.12.2022 22:00

Thank you so much for this approach ... this is really easy

Ответить
@duck3072
@duck3072 - 21.11.2022 15:40

Can we solve problems by filling dp from last cell to first

Ответить
@kpjVideo
@kpjVideo - 31.10.2022 05:12

Great explanation! This helped a bunch!

Ответить
@shivanshpareek7278
@shivanshpareek7278 - 01.09.2022 13:28

please add the link as well and ur playlists are best way to revise and the way you explain gives me confidence to speak in interviews ..
Thanks a lot for amazing content

Ответить
@shouryagupta8763
@shouryagupta8763 - 07.08.2022 16:16

thanks a lot didi!

Ответить
@anshulbhati5752
@anshulbhati5752 - 02.08.2022 21:43

greatt explanation!

Ответить
@rudrakshsharma4601
@rudrakshsharma4601 - 20.07.2022 13:53

nice work alisha

Ответить
@anupamojha3836
@anupamojha3836 - 12.07.2022 15:14

very nice explaination

Ответить
@prasannaprabhakar1323
@prasannaprabhakar1323 - 05.07.2022 11:24

The way you are conveying the intuition part of the solution creates the difference.
Nice choice of questions btw.

Ответить
@vikashdhania2970
@vikashdhania2970 - 18.06.2022 16:02

thanks mam

Ответить
@shivanshyadu4830
@shivanshyadu4830 - 13.06.2022 11:51

Ufff didi one of the best place and you just explained the code in really easy way, I saw everyone's video but they just copy pasting the solution ❤❤😊

Ответить
@willingtushar
@willingtushar - 18.12.2021 05:42

Nice explanation Indeed!

Ответить