DP 55. Maximum Rectangle Area with all 1's | DP on Rectangles

preview_player
Показать описание

Please watch the video at 1.25x for a better experience.

a

In this video, we solve the Maximum Rectangle Area with all 1's problem.

Рекомендации по теме
Комментарии
Автор

I am not sure whether you would be seeing this or not but I want to thank you for all the playlists (dp, graph, tree, recursion, placement series and the sde sheet) every content I have covered and just in 2 weeks literally just after giving proper 2 weeks to all the problems you have created I was able to clear all the amazon coding interviews. Not sure whether I would be able to clear the manegerial round but I have come so far because of the content you created. Not only amazon, Qualcomm, Vmware every where I am able to clear the rounds because solely of your content. Waiting for more content. Keep the great work going.

sunavaroy
Автор

Special thanks to you for making a clarification on why this problem is in DP playlist.

varungurnani
Автор

This problem came in my Internship test. Unfortunately, i was unable to solve it and scared from this question. My bad, i haven't look youtube at that time. Gladly, i found a mentor to teach me this.

salmanahmedkhan
Автор

man am feeling proud of myself i was so consitent in this series of the dp. i watched i code every single question. thank you striver bhaiya...

devbhattdev
Автор

Those who are getting wrong answer in Leetcode, In the function they gave the 2d character vector(matrix) not integer vector, so instead of writing matrix[i][j]==1 write matrix[i][j]=='1' then everything will be fine

naveensaicremsiyadlapalli
Автор

Understood!! Thank you Striver for this amazing playlist and kudos to all the hard work you've put in to bring us this amazing content!!

RamyasriMedagam
Автор

Oh nice building up on previous concepts. Understood, thanks!

sauravchandra
Автор

Thanks striver for giving line of thinking that's the most difficult thing for me! Leap of faith🎉

dashsights
Автор

this blew my mind, on god, hats off man!

ChewyPopcorn
Автор

The time complexity will be O(n* (m+m)) instead of O(n*(m+n)). because the row size=m and size of height vector=m

vishalsinghrajpurohit
Автор

I think the time complexity would be O(n*m) + O(n*O(m))
O(n*m) because there are 2 loops and O(n* m) is for finding max area in histogram for each row and there are total n rows.

gandhijainamgunvantkumar
Автор

at 6:06 shouldn’t it be 3? there are 3 1’s together so 3*1=3

prabhpreetsingh
Автор

Understood! Thank you sooo much for your great work!!

cinime
Автор

You have explained it very well sir, thanks for such a wonderful video

ronakslibrary
Автор

Hard Problems are many times easy. But, with a difficult approach to come up with.

daranip
Автор

In case, if you are curious to solve using Recursive Solution:: Here is the memoized recursive solution(in JAVA):-
(I HAVE ABSTRACT OUT THE MAX HISTOGRAM FUNCTION) :-)
public int maximalRectangle(char[][] matrix) {


int[]dp = new int[matrix.length];
for(int i = 0; i < dp.length; i++)
{
dp[i] = -1;
}
int[]heights = new int[matrix[0].length];

return maxRec(0, matrix, heights, dp);
}

public int maxRec(int i, char[][] matrix, int[]heights, int[]dp)
{
if(i == matrix.length)
{

return 0;
}

if(dp[i] != -1)
{
return dp[i];
}
int[] temp = new int[heights.length];
for(int j = 0; j < heights.length; j++)
{
if(matrix[i][j] == '1')
{
heights[j]++;
// System.out.println("+1");
}
else
{
heights[j] = 0;
}
}

for(int k = 0; k < temp.length; k++)
{
temp[k] = heights[k];
}

int rec = maxRec(i + 1, matrix, heights, dp);

for(int k = 0; k < temp.length; k++)
{
heights[k] = temp[k];
}
int height =

int ans = Math.max(height, rec);

dp[i] = ans;
return ans;
}

vinayjangra
Автор

max area of second row rect should be 3 not 2

punkstAr
Автор

Time complexity is O(n*m) not O(n*(n+m))

kanakbanerjee
Автор

for max area of row 2...why won't it be 1x3 ??

aizadiqbal
Автор

Today I came to know why all my seniors and batchmates, say about Striver . Such a beautiful explanation 🫡

lazymethisside
welcome to shbcf.ru