I am watching the solution after the interview. I was asked how and why we were moving two pointers. I got the answer. We have to find a minimum of two heights of left and right pointer Since we are decreasing the width, to maximize the water contained we will move the pointer pointing to a smaller height.
Thank you so much. When I first read the question I was afraid that its too difficult and when you read the question I was able to do it on my own without listening to the whole explanation.
bhaeeya if index 2 pey 6 ki jagah koi bara number hota jaisey 45 to area hamara chut jata na ,kiwki dono height same hai start and end ka if uskey neigher ka height bara ho to compare krna pareyga na kis side move krey i ko ya j ko hope mai smjha paya apna question
in that we were seeing consecutive heightss to form a rectangle by using the concept of nsl and nsr of stack by taking the current idx height but there isnt any consecutiveness , but here we are storing the water even if the heights in b/w are smaller or bigger we can take them cos water will be stored b/w so we dont care what heights are coming in b/w but in the histogram one if the fluctuation of heights occured our rectangle will be disformed which we dont want
when the height is same why are we allowed to shift any of them i and j . because in the above question when both i and j if we move i then the maxArea is 24 but if we move from j then it will be 16
class Solution { public: int maxArea(vector& height) { // find length // find height int n = height.size(); int left = 0; int right = n -1; int maximum = INT_MIN; while (left < right) { int l = right - left; int h = std::min(height[left], height[right]); (height[right] > height[left]) ? left++ : right--; int k = l * h; if (k > maximum) { maximum = k; cout
He never asked us for like , share and subscribe 🙇♂. A True GEM...
Question is so intimidating i have seen this question and left it right away
I am watching the solution after the interview.
I was asked how and why we were moving two pointers.
I got the answer.
We have to find a minimum of two heights of left and right pointer
Since we are decreasing the width, to maximize the water contained we will move the pointer pointing to a smaller height.
which Company Bro?
Ur explanations , the way of teaching .... big fan sir really feeling blessed
Awesome explaination. Thank you!
I’m glad you enjoyed it! 🙏
Amazing explanation
Sir kya smjaya 🔥❤
Thank you so much. When I first read the question I was afraid that its too difficult and when you read the question I was able to do it on my own without listening to the whole explanation.
same
nice solution and well explained.
You are the best bro !!!🙏🙏
And so are you Prashu
Thank you so much 🙏❤️😇
great explanation
Thank You Mik...
god level explanation brother
cant we apply trapping rain water problem logic with modification ?
omg why i didn't find this channel earlier
bhaeeya if index 2 pey 6 ki jagah koi bara number hota jaisey 45 to area hamara chut jata na ,kiwki dono height same hai start and end ka if uskey neigher ka height bara ho to compare krna pareyga na kis side move krey i ko ya j ko hope mai smjha paya apna question
thanks
what is 8*8 =64 is it max?
sir how this question is different from maximum area histogram
same doubt
in that we were seeing consecutive heightss to form a rectangle by using the concept of nsl and nsr of stack by taking the current idx height but there isnt any consecutiveness , but here we are storing the water even if the heights in b/w are smaller or bigger we can take them cos water will be stored b/w so we dont care what heights are coming in b/w but in the histogram one if the fluctuation of heights occured our rectangle will be disformed which we dont want
when the height is same why are we allowed to shift any of them i and j . because in the above question when both i and j if we move i then the maxArea is 24 but if we move from j then it will be 16
same question
whatever you choose .. will it effect maximum?
Bhai aapke subscriber bhut tezz badd rhe
Badhai ho
class Solution {
public:
int maxArea(vector& height) {
// find length
// find height
int n = height.size();
int left = 0;
int right = n -1;
int maximum = INT_MIN;
while (left < right) {
int l = right - left;
int h = std::min(height[left], height[right]);
(height[right] > height[left]) ? left++ : right--;
int k = l * h;
if (k > maximum) {
maximum = k;
cout
Day 3
class Solution {
public:
int maxArea(vector& height) {
int maxwater = 0;
int left = 0;
int right = height.size()-1;
while(left < right){
maxwater = max(maxwater, min(height[left], height[right])*(right-left));
if(height[left] < height[right]){
left++;
}
else{
right--;
}
}
return maxwater;
}
};
Thankyou
You’re welcome 😊