LeetCode #11: Container with most Water | Facebook Interview Question | C++

  Рет қаралды 60,418

Knowledge Center

Knowledge Center

Күн бұрын

Пікірлер: 39
@AnandKumar-ed3yo
@AnandKumar-ed3yo 4 жыл бұрын
Nice explanation. we can Generalize as below. int maxArea(vector& height) { int maxarea =0; int minIndex = 0; int maxIndex = height.size()-1; while(minIndex!=maxIndex) { if(height[minIndex]>height[maxIndex]) swap(minIndex,maxIndex); int newarea = height[minIndex] * (abs(minIndex-maxIndex)); if(newarea>maxarea) maxarea = newarea; if(minIndex > maxIndex) minIndex--; else minIndex++; } return maxarea; }
@avivfriedman
@avivfriedman Ай бұрын
If someone wants a short summary: The idea is to calculate the area between the lines at the two pointers, update the maximum area if the current area is larger, and then move the pointer pointing to the shorter line. By moving the shorter line, you potentially increase the height of the container, as increasing the width alone won't give a better result if one side is short.
@ForCodingInterview
@ForCodingInterview 3 жыл бұрын
class Solution { public: int maxArea(vector& height) { int i = 0, j = height.size()-1; int m = 0,m1; while(i
@ajnabee01
@ajnabee01 3 жыл бұрын
One line sums up it all: If you have the max width between two bars, then the only way to increase the area is to increase the height. That is, the current area is the maximum for the area for the solution set containing the current minimum height bar.
@saivenkat9113
@saivenkat9113 3 жыл бұрын
U made my bulb glow just with one line Thanks!
@Bad_Avadh
@Bad_Avadh 2 жыл бұрын
better approaches int area; int maxarea=0; int start=0; int end=height.size()-1; while(start < end){ * we going to find the area of container* area=min(height[start], height[end])* (end-start); * after finding the area we check that if area is grater than maxarea we place the area value into maxarea* if(area > maxarea){ maxarea= area; } *after that we check that start value is less that end value than increment the start or else decrement the end index value* if(height [start] < height[end] ){ start++; } else { end--; } } return maxarea; please comment if any query is there?? thank you
@RajeevCanDev
@RajeevCanDev Жыл бұрын
MY approach is way better btw bcuz we dont need to mutate the min height and idx simple and better int maxArea(vector& height) { // Write your code here. int ans = 0, n = height.size(); int i = 0, j = n-1; while(iheight[j]){ ans = max(ans, (j-i)*height[j]); j--; } else{ ans = max(ans, (j-i)*height[i]); i++; } } return ans; }
@heyrmi
@heyrmi 3 жыл бұрын
I watch your videos for intuition. Then take time to code that logic.
@quant-prep2843
@quant-prep2843 3 жыл бұрын
remember during the interview nobody will give you the intuititon, lol
@heyrmi
@heyrmi 3 жыл бұрын
@@quant-prep2843 working on it 😅
@VishnuManojkumar-i3f
@VishnuManojkumar-i3f 3 ай бұрын
class Solution { public: int maxArea(vector& height) { int left=0; int right=height.size()-1; int max_area=0; while(left
@kolanaresh7077
@kolanaresh7077 2 жыл бұрын
nice explanation,first problem i seen algorithm and solved my own.
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Well done
@kolanaresh7077
@kolanaresh7077 2 жыл бұрын
int maxArea(vector& height) { int n=height.size(); int i=0,j=n-1; int area1=0; int area; int width; int hmin; while(iheight[j]) { hmin=height[j]; j--; } else { hmin=height[i]; i++; } area=width*hmin; if(area>area1) { area1=area; } } return area1; }
@poojaagarwal1480
@poojaagarwal1480 4 жыл бұрын
Wow! Great Solution!
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Glad you like it!
@ashishmadan5700
@ashishmadan5700 3 жыл бұрын
Amazing explanation !!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks.
@TheMsnitish
@TheMsnitish 3 жыл бұрын
What kind of hardware you use for the pen ? Please share the amazon link if you have of the pen and digital slate you are using.
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Hi. This is the pen. amzn.to/3tOVEP3
@TrackToPune
@TrackToPune 2 жыл бұрын
code quality is not good simple solution class Solution { public: int maxArea(vector& height) { int maxArea = 0; int i = 0, j = height.size() - 1; while(i < j) { maxArea = max(maxArea, min(height[i], height[j]) * (j - i)); if(height[i] < height[j]) i++; else j--; } return maxArea; } };
@paragroy5359
@paragroy5359 4 жыл бұрын
Nice explanation sir....
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Thanks for liking
@sayantaniguha8519
@sayantaniguha8519 2 жыл бұрын
What is the difference b/w this Q and *Largest Rectangle in Histogram* ?
@quangxiang3382
@quangxiang3382 4 жыл бұрын
Weiting fore premiere
4 жыл бұрын
Your explaination is good but your demo code is quite long. We just need to keep track left_height and right_height (with only 1 while loop)...anyway, thank you very much for your video.
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
Noted
@ramfattah275
@ramfattah275 3 жыл бұрын
@@KnowledgeCenter this video is perfect 👍 as long as its not over 30 mins long🤣!! thanks for creating this C++ playlist
@TheMsnitish
@TheMsnitish 3 жыл бұрын
Bhai do you also plan to make videos in Hindi ?
@quant-prep2843
@quant-prep2843 3 жыл бұрын
there is no bhai's,this is for all dont be a discriminant and gender based inequality
@TheMsnitish
@TheMsnitish 3 жыл бұрын
@@quant-prep2843 LMAO what's wrong with you ? Bhai doesnt mean what you have assumed to be. I hope you know that it is just a way to address someone politely,
@AMITVERMA-p5r
@AMITVERMA-p5r Жыл бұрын
question ka link to provide kara dena chaiye
@tusharnain6652
@tusharnain6652 2 жыл бұрын
This code is quite big, this can be done simply with only 1 while loop/
@damudaran3765
@damudaran3765 4 жыл бұрын
its a good explaination . but u are just telling the thing but u r not concernerd about the viewers understanding . be bold on your voice .
@aidanthompson5053
@aidanthompson5053 Жыл бұрын
4:32
@burakgunes2535
@burakgunes2535 2 жыл бұрын
is that a correct answer ? #include #include #include using namespace std; int sum; unsigned int maxArea; int area; int i, j; int minArea = 213213; int main() { maxArea > 0; area > 0; valarraya(9); a = { 1,8,6,2,5,4,8,3,7 }; for (int i = 0; i < 9; i++) { for (int j = 1; i+j < 9; j++) { if (a[i] >= a[i + j]) { area = j * a[i + j]; //cout area) { minArea = area; } //cout
FAANG Coding Interview Question - Container With Most Water (LeetCode)
13:30
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН
LeetCode #202: Happy Number | Facebook Interview Question | C++
14:38
Knowledge Center
Рет қаралды 14 М.
Container with Most Water - Leetcode 11 - Python
12:37
NeetCode
Рет қаралды 365 М.
LeetCode #91: Decode Ways | Facebook Coding Interview
13:16
Knowledge Center
Рет қаралды 20 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 253 М.
Easy Google Coding Interview With Ben Awad
28:00
Clément Mihailescu
Рет қаралды 1 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 674 М.
Medium Google Coding Interview With Ben Awad
51:27
Clément Mihailescu
Рет қаралды 1,3 МЛН
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН