Largest Area under Histogram efficient algorithm using Stack | Coding Interview Question

  Рет қаралды 62,260

Coding Blocks

Coding Blocks

Күн бұрын

How to find out the largest area under Histogram in a Stack ? Learn to solve in this tutorial :)
For more online courses visit - www.codingblock...
Check courses on - online.codingbl... [Free Trial Available]
Coding Blocks is pleased to announce courses like C++ and Java, Data Structures and Algorithms, Web and Android Development(Java and Kotlin), Competitive Programming, Coding Interview Preparation and Machine Learning, AI and more.
#CodingBlocks #ProgrammingMadeEasy #LearnCodingOnline
Like our FaceBook Page - / codingblocksindia
Follow us on Instagram - / codingblocks
Follow us on Twitter - / codingblocksin
Source code available on -github.com/cod...
For more interesting tutorials - / @codingblocksindia

Пікірлер: 110
@noone_and_nobody
@noone_and_nobody 4 жыл бұрын
I went through atleast a few videos before giving this one a try and boy, it was completely worth it. The explanation with a running example, just superb. Kudos to the team!
@NareshKumar-dw9xp
@NareshKumar-dw9xp 4 жыл бұрын
This is the best explanation I have ever seen about any question. Everyone is running behind codes but no one is talking about mathematics behind that. I have seen a lot of videos related to this but did not satisfy. But now I am fully confident in these problems. Thank you so much , you always use to explain hard problems in quite easy manner .
@kvishalreddy_3742
@kvishalreddy_3742 3 жыл бұрын
best explanation thanks
@baurks
@baurks 6 жыл бұрын
The best explanation so far. I am still lagging behind on the intuition, but now I can prove the algorithm by induction.
@cyanzhoufeng
@cyanzhoufeng 4 жыл бұрын
I don't know why so many ppl downvote this excellent presentation , this is best explanation I found, rather than other videos which just show the formula and conclusion only. Thanks for the detailed illustration
@tusharsinha1772
@tusharsinha1772 4 жыл бұрын
The only explanation on youtube for this problem which makes sense.
@JuanSB827
@JuanSB827 5 жыл бұрын
Finally an explanation that makes sense!
@vanshthukral5477
@vanshthukral5477 5 жыл бұрын
Expressing my gratitude to everyone who made creation of this video possible.A really simple ,thorough and good explanation.
@CodingBlocksIndia
@CodingBlocksIndia 5 жыл бұрын
Thanks Vansh !!
@mello.maniac
@mello.maniac 7 жыл бұрын
the approach was nice, I liked the explanation with a proper example, Just one suggestion: please remove double logos from the bottom right corner.
@SlyGoblin927
@SlyGoblin927 4 жыл бұрын
Dude, you saved my day. all the remaining videos were a waste of time. 🤔 I wonder how the hell did the first person who solved this question in the world got this idea or thought of this algorithm. It's just amazing 🤯
@aasdffew
@aasdffew 4 жыл бұрын
He must have been a genius...
@saurabhverma2729
@saurabhverma2729 4 жыл бұрын
I feel the same for the person who designed this problem.
@ananyasharma101
@ananyasharma101 4 жыл бұрын
Best solution to this problem among all videos
@shagun9155
@shagun9155 3 жыл бұрын
Woow what a worthy explanation:-) only now I am able to get the intuition of this problem
@CodingBlocksIndia
@CodingBlocksIndia 3 жыл бұрын
Great. Keep Learning with Coding Blocks!
@AmanKumar-hr5dc
@AmanKumar-hr5dc 4 жыл бұрын
Very nice explanation Now i got the intution behind this!
@sachingoyal6197
@sachingoyal6197 6 жыл бұрын
Finally got it after going through so many videos.
@venuvenu2719
@venuvenu2719 5 жыл бұрын
I still have no idea how someone gets idea to use stack for this problem
@harshitsaini15
@harshitsaini15 5 жыл бұрын
@@venuvenu2719 Yes, I'm thinking the same :(
@swapnikapandey6882
@swapnikapandey6882 4 жыл бұрын
easiest explanation so far.Keep making such videos.
@WimpyWarlord
@WimpyWarlord 6 жыл бұрын
Set the speed to 1.25 or 1.5 and thank me later. The video was a lot better than others made on similar topic , yet you would have to develop the intuition on your own .
@aasdffew
@aasdffew 4 жыл бұрын
Now I am able to understand the logic, thanks
@anirudhatalmale5575
@anirudhatalmale5575 4 жыл бұрын
The best and simplest explanation.
@ShaliniNegi24
@ShaliniNegi24 5 жыл бұрын
Honestly very nice explanation.
@rajugaurav5052
@rajugaurav5052 4 жыл бұрын
Thank you so much , finally I understand the intuition behind this algorithm :))
@nayankhuman1043
@nayankhuman1043 4 жыл бұрын
best explanation ever
@katyayanikrishnan8725
@katyayanikrishnan8725 4 жыл бұрын
best video so far on this topic.
@ajitdavis5100
@ajitdavis5100 4 жыл бұрын
very well explained thank you so much
@sakibthetech
@sakibthetech 4 жыл бұрын
best explanation..Thanks
@sprajapati2011
@sprajapati2011 5 жыл бұрын
You just ammmazingly explained.
@CodingBlocksIndia
@CodingBlocksIndia 5 жыл бұрын
Thanks💕
@nafishaftab9323
@nafishaftab9323 5 жыл бұрын
Best explanation.....even better than geeksforgeeks
@sukritkapil2562
@sukritkapil2562 4 жыл бұрын
Nice explanation. Thanks!
@HumorHubIndi
@HumorHubIndi 4 жыл бұрын
Thanks a lot..grt explanation..excellent work!!
@israelmcculley2927
@israelmcculley2927 3 жыл бұрын
I found your explanation confusing because the first step you explained was that you would only push an index onto the stack if the height is larger than the previous height, but then you went on to push literally every single element into the stack regardless of its height comparison with the previous height.
@ujjvalsharma5055
@ujjvalsharma5055 4 жыл бұрын
I really appreciate what you did here. Amazing work and such explanation was missing in others. I encourage to put out more video and keep up the good work.
@reassume4826
@reassume4826 4 жыл бұрын
Thank You Coding Blocks.
@ajaygaur3392
@ajaygaur3392 6 жыл бұрын
explanation starts at 11:00 and it is great
@tushargupta1107
@tushargupta1107 4 жыл бұрын
thanks bro
@imalive404
@imalive404 6 жыл бұрын
By far the best video on this problem. Kudos _/\_
@CodingBlocksIndia
@CodingBlocksIndia 6 жыл бұрын
Thanks!! Do Subscribe for more such videos
@sanketkale730
@sanketkale730 4 жыл бұрын
Thnax man...really helpful!! keep it up!
@harshitsaini15
@harshitsaini15 5 жыл бұрын
This is one hell of a notorious problem I have ever seen and the most fabulous explanation given for it :)
@mohammedsuhailbasha4860
@mohammedsuhailbasha4860 6 жыл бұрын
Very nice lecture...... always upload this type of lectures bro.this will more helpful to us
@CodingBlocksIndia
@CodingBlocksIndia 6 жыл бұрын
Check out complete course at online.codingblocks.com
@vartikavarshney8303
@vartikavarshney8303 5 жыл бұрын
its long but definitely worth it
@sachingarg4385
@sachingarg4385 4 жыл бұрын
That's what she said :p
@prateekmishra6245
@prateekmishra6245 3 жыл бұрын
@@sachingarg4385 :)
@rishulmatta16
@rishulmatta16 7 жыл бұрын
Amazing explanation loved it! Scroll to 13:41
@punitpawar4231
@punitpawar4231 4 жыл бұрын
Thanks for this video. Nice Explanation. Where is the video or the link to the code ?
@participiopassado
@participiopassado 5 жыл бұрын
Thank you very much for the explanation. Now I finally understood this question! Subscribed!
@CodingBlocksIndia
@CodingBlocksIndia 5 жыл бұрын
Thank you so much !!
@jeeruajay2111
@jeeruajay2111 7 жыл бұрын
Very good Explination
@piyushjaiswal4866
@piyushjaiswal4866 5 жыл бұрын
Example is same as in GFG article
@sumanreddyg8245
@sumanreddyg8245 6 жыл бұрын
@ 7:46 you explained [R-L-1] * hight of the minimum current bar popped from stack , again in the diagram L = 0 and R=4 then its [4-0-1]*3 = 9 right .. and why there is extra -1 in the formula [R-L-1] , also i understood L and R bars height is less than the current bar popped up from the stack please explain this point , apart from this every thing is understood
@anshusharma1983
@anshusharma1983 5 жыл бұрын
If index 4 is the right hinderance and 0 index is the left hinderance. Then the rectangle consists of indexes 1, 2 & 3. Hence (R-L) -1 i.e. (4-0)-1 as the left is not inclusive, it is the hinderance before the last bar. Hope this helps
@MaulikSakhida
@MaulikSakhida 6 жыл бұрын
7:45 Area = (R - L - 1) * Height of current bar, So It should be, Area = (4 - 0 - 1 ) * 3 ?
@VishalKumar-kr9me
@VishalKumar-kr9me 5 жыл бұрын
Yes you are r8...He has written that by mistake...
@agrox29
@agrox29 4 жыл бұрын
Glad to see so many paid comments here
@bvsrevanth6856
@bvsrevanth6856 4 жыл бұрын
I actually like their explanation ,but this is one of the worst explanation I have ever seen
@mayurkoli4145
@mayurkoli4145 4 жыл бұрын
what if bar's are in increasing order eg -> 1, 2, 4, 5, 6, 7
@zod1ack_csgo_clips425
@zod1ack_csgo_clips425 4 жыл бұрын
It will be the worst case scenario for this algo with O(2n) complexity.
@akshbansal7715
@akshbansal7715 4 жыл бұрын
We can add 0 at the end of the array.
@shivampawar5074
@shivampawar5074 4 жыл бұрын
But what if the numbers are in increasing order e.g. 1,2,3,4,5 ?
@ManishKumar-zt5sk
@ManishKumar-zt5sk 5 жыл бұрын
great explanation once again!!!!!!!!!
@CodingBlocksIndia
@CodingBlocksIndia 5 жыл бұрын
Thanks Manish
@suharajsalim4549
@suharajsalim4549 4 жыл бұрын
Thanks a lot :)
@ShubhamKumar-rt8nb
@ShubhamKumar-rt8nb 5 жыл бұрын
Finally I understood it
@CodingBlocksIndia
@CodingBlocksIndia 5 жыл бұрын
Glad you liked our video.
@farhan787
@farhan787 5 жыл бұрын
For O(n^2) solution, how would I be able to know that what is the minimum height bar in (i, j) range ? at 2:30
@MohitKumar-yr4rl
@MohitKumar-yr4rl 4 жыл бұрын
My solution #include using namespace std; int local_min(int arr[],int i,int j) { int min=arr[i]; for(int p=i+1;parr[p]) min=arr[p]; } return min; } int main() { int arr[]={6,2,5,4,5,1,6}; int n=7; int area=0; for(int i=0;i
@rhythmbhatia8906
@rhythmbhatia8906 4 жыл бұрын
// Largest area under histogram // O(n^2) #include #include using namespace std; int histogram(int a[],int n) { int min,area,i,j,ans=0; for(i=0;in; for(i=0;i>a[i]; cout
@devcoder3107
@devcoder3107 4 жыл бұрын
Please add code section in description.
@RAJPATEL-nm9nz
@RAJPATEL-nm9nz 5 жыл бұрын
very good eplanation bt initial 10mins are boring.
@giangkhuat9343
@giangkhuat9343 5 жыл бұрын
Thanks a lot ! I was able to follow through and wrote the code myself. Best explaining video so far on this problem
@CodingBlocksIndia
@CodingBlocksIndia 5 жыл бұрын
Thanks Glang for the compliment. please subscribe for more such videos.
@jeeruajay2111
@jeeruajay2111 7 жыл бұрын
Sir, I didn't find this type of video. Extraordinary ,,super,,
@The_Helping_Hand_1997
@The_Helping_Hand_1997 6 жыл бұрын
Thanks Sir...
@VishalKumar-kr9me
@VishalKumar-kr9me 5 жыл бұрын
WHAT IF THE CURRENT NUMBER IS EQUAL TO THE TOP OF THE STACK???????
@riddhidutta7411
@riddhidutta7411 7 жыл бұрын
I coded according to your algorithm...ideone.com/LjOjXm (my solution) but in www.spoj.com/problems/HISTOGRA/ its giving tle....pls help
@yashbhardwaj7756
@yashbhardwaj7756 4 жыл бұрын
please provide the code as well
@ArpitDhamija
@ArpitDhamija 6 жыл бұрын
How to open the source code on GitHub
@MDMIRU152
@MDMIRU152 3 жыл бұрын
Ok
@adityavandansharma1575
@adityavandansharma1575 5 жыл бұрын
* shows gratitude *
@ManishThakur-jp7zm
@ManishThakur-jp7zm 4 жыл бұрын
watch at *1.5, your welcome!
@sulaimant5690
@sulaimant5690 4 жыл бұрын
thenks.
@sambhumahato8320
@sambhumahato8320 4 жыл бұрын
wow!
@Great_one1
@Great_one1 5 жыл бұрын
can u please prove us the code?
@ayushaggarwal4714
@ayushaggarwal4714 4 жыл бұрын
You just can't do this on your own right?
@yatharth_er
@yatharth_er 7 жыл бұрын
nice
@Oswee
@Oswee 7 жыл бұрын
Aaaand.... what is the real-world use case of this? Why would i need this?
@zyro9922
@zyro9922 6 жыл бұрын
0:26
@piyushjaiswal4866
@piyushjaiswal4866 5 жыл бұрын
This is not any valid reason that pop and push only once make it O(n)
@ayushthakur733
@ayushthakur733 4 жыл бұрын
came here with some expectations , explanation is not good i didn't understand any part of it
@sommayghosh4617
@sommayghosh4617 4 жыл бұрын
worth watch for 30 mins !
@TheRkrrockstar
@TheRkrrockstar 4 жыл бұрын
so many ads
@premangraithatha8273
@premangraithatha8273 4 жыл бұрын
i don't understand anything
@nicolasgoosen5142
@nicolasgoosen5142 3 жыл бұрын
Thanks for the useful video, but, man, I never heard such a monotonous voice drawing out it's words in such a dull and languid way. Sheesh!
@abhishekagarwal2522
@abhishekagarwal2522 6 жыл бұрын
What if the first bar is of 100 units alone.
@abhishekagarwal2522
@abhishekagarwal2522 6 жыл бұрын
Its own area will be 100*1=100
@ciphertester1147
@ciphertester1147 6 жыл бұрын
Thanks for making your video but your area calculation creates too much magic. If you code this you will find your containers are missing important data. Using a stack you need to keep the height as well as the valid starting point. Using your example the data would look like these pairs (6,0),(2,1),(5,2),(4,2),(1,0),(6,6). It would be to your benefit to code this before teaching/explaining to others. Here's a test case I used : {2,6,3,2,5,5,5,4,4,5,1,7}. Happy Hacking!
@shauvikpujari9522
@shauvikpujari9522 4 жыл бұрын
Explanation is outstanding keep it up bro👍
Largest rectangle in Histogram | Leetcode #84
27:43
Techdose
Рет қаралды 112 М.
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Рет қаралды 518 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
Google Coding Interview With A Competitive Programmer
54:17
Clément Mihailescu
Рет қаралды 2,5 МЛН
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 4,2 МЛН
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 16 МЛН
L12. Largest Rectangle in Histogram | Stack and Queue Playlist
31:42
take U forward
Рет қаралды 68 М.
But what is a neural network? | Deep learning chapter 1
18:40
3Blue1Brown
Рет қаралды 18 МЛН
How the C++ Compiler Works
17:55
The Cherno
Рет қаралды 844 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН