One thing I want to point out is that, in interview, there are some scenarios when only brute force solution exists to the given problem. And its important to understand that even though solution is not optimal, it has given the solution indeed. So, optimal solution is not always guaranteed, even though it exists in this problem. Nevertheless, great video @takeUforward, the best explanation for this problem I found so far. 🤟
@bhagyashri77292 жыл бұрын
yes, I am just bothered with too much to remember - formula and technique :(
@manojnavinjamuri5867 Жыл бұрын
Thank you for such amazing explanation. I cant find a single video of others who explain with such clarity. No matter who criticize you continue the work u r doing.
@nonamenoname2801-xj5 Жыл бұрын
Anyone who is not able to understand the solution....I would highly recommend aditya verma's solution ....THAT MAN IS A GOD
@stutisuchak45252 жыл бұрын
I saw multiple videos on this question, but this one made it clear. Thank you so much.
@localhost_30002 жыл бұрын
Here is the complete optimized algorithm... 1. create a stack st that will store indexes 2. create two arrays left_smaller and right_smaller that will store leftmost smaller and rightmost smaller index for an index i respectively. // calculate left smaller... 3. for every arr[i]: i. curr_height = arr[i] // stack_top_height means arr[st.top()] ii. while stack is not empty and stack_top_height >= curr_height: -> stack.pop() iii. if stack is empty left_smaller[i] = 0 else left_smaller[i] = st.top() + 1 iv. st.push(i); end for loop 4. clear stack for reuse // calculate right smaller...this time traverse from the back.. 5. for every arr[i] i. curr_height = arr[i] ii. while stack is not empty and stack_top_height >= curr_height: stack.pop() iii. if stack is empty right_smaller[i] = n-1 else right_smaller[i] = st.top() - 1 iv. st.push(i) end for loop 6. max_area = INT_MIN 7. for every arr[i] i. curr_height = arr[i] ii. width = (right_smaller[i] - left_smaller[i] + 1) iii. max_area = max(max_area, curr_height * width) end for loop 8. return max_area Any feedback will be appreciated
@sahityavatturi1212 жыл бұрын
👏
@nihalsingh62339 ай бұрын
00:01 Understanding how to find the largest rectangle area in a histogram. 02:09 Selecting the maximum area rectangle in histogram 05:43 Calculating the area of rectangles with different heights and consecutive widths. 07:44 Discussing how to find the largest area of a histogram by considering different heights and widths 11:59 Brute force solution has O(n^2) complexity 13:50 Using a stack to find left smaller boundary indexes 17:30 Identifying left smaller elements and calculating boundaries in a histogram. 19:15 Computing left and right smaller indexes using a stack 22:45 Compute the largest rectangular area in histogram 24:34 Using stack method to find left smaller and right smaller, leading to largest rectangular area. 27:53 Using stack to find left and right smaller elements for histograms. 29:27 Optimal solution explained using a 6-line code and single pass of left smaller to find maximum rectangle area
@mukeshmahajan15863 жыл бұрын
bhai the energy with which u explain incredibly amazing!
@thisisankitgaur3 жыл бұрын
❤️ from IIT Bombay. Nice Work!!
@trojanhorse8278 Жыл бұрын
Hum log Mtech wale hai , hame dekhna padta hai :}
@Aditya-m4r6v Жыл бұрын
Or bhai kaha lgi placement
@phantomhawk48911 ай бұрын
@@Aditya-m4r6v bhai usse shadi karoge kya?
@MPrachiShinde7 ай бұрын
Flex karne ka tareeka thoda kezual hai
@ankitsablok9522 жыл бұрын
Really liked the intuition you developed with boundaries. Thoroughly impressed by the way you have explained this problem. I solved this problem using the boundary approach you mentioned :). Pretty nice explanation as I can imagine its hard to put this complex a thought into appropriate words.
@takeUforward2 жыл бұрын
There is a part-2 as well
@akshyagarg23983 жыл бұрын
best. Liked the way to optimize the brute force. Other youtuber just directly jump on optimal solution.
@anshuljain17003 жыл бұрын
Wish i could like it millions of time❤️ Never have I ever seen such a great video❤️ Superb explanation 👍 Tried your best to embibe intuition👍❤️
@DeepakKumar-yc9hr3 жыл бұрын
you are a diamond ... no one can replace you bro ... .
@stith_pragya10 ай бұрын
UNDERSTOOD.......Thank You So Much for this wonderful video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@susrandomguy2 жыл бұрын
9:27 enjoy. btw great video as usual.
@prabhakaran55424 ай бұрын
Understood ❤❤❤ watching in 2024!
@prabhakaran55424 ай бұрын
July 1st
@sandeshkumarchandrakar16223 жыл бұрын
just solved before video got released now this masterpiece comes thanks for efforts sir
@narendrakumariitb2 жыл бұрын
Thanks Striver for such a neat explanation. Intuition is to store next smaller and previous smaller value(here index) for current value in two separate arrays and then use this approx formula currentHeight * (currentNextSmallerValue - currentPreviousSmallerValue) for current index. Take the max out of this to get desired output
@yashkumardhawan6961 Жыл бұрын
The solution is well explained. Also, please add this shirt to your merchandise collection.
@nehasingh81816 ай бұрын
Great job! You explain every concept so easily.....
@sunnykumarpal96792 жыл бұрын
Bhaiya you teaching is really fabulous . I enjoy learning from your videos.
@prateekshrivastava28026 ай бұрын
Striver The Real OG !! Period : )
@AshishKumar-pq6pr3 жыл бұрын
Best explanation...maja aa gya 😅🤟
@hell-o84703 жыл бұрын
How to get logic of sub problems in mind ? The moment you told next greater element at 13:05 . I immediately got the idea how to solve and got AC in one go as I had solve next greater element problem. But "how do we get that sub concept at right time? "
@rydmerlin Жыл бұрын
This assumes you have smaller on both left and right but you aren’t always going to expect that. You can have increasing from left to right or decreasing from left to right.
@teacup1431 Жыл бұрын
Can we do sorting and take product of each element and number of remaining elements . It can be done in one loop
@sourabhsisodia95633 жыл бұрын
striver bhai tum bhot mast kam krta hain....
@harshkumarsharma11697 ай бұрын
18:21 Is this just me who listened to some other noise here
@hariomtiwari7605 Жыл бұрын
Superb Explanation Bhaiya 👌👌👌👌
@rebellious_7032 жыл бұрын
Wah Arnab Wah ❤
@Sneha-qz9ml3 жыл бұрын
The best explanation found!!..............
@democratcobra2 жыл бұрын
Superb explanation ....
@yashwagh833 жыл бұрын
That T-shirt lol! But keep up with the good work, you explain shit very well!
@ShubhamMahawar_Dancer_Actor3 жыл бұрын
The link you have provided for part2 is the link of Part 1 .reverify it.
@sagarlandge32712 жыл бұрын
crisp and clear!
@studyaccount7942 жыл бұрын
Amazing explanation man!! Coded the brute-force myself after just watching the 1/3rd of the video. You're doing god's work!!
@AKASHTHAKUR-rs4sg2 жыл бұрын
Happy Guru Purnima @StriverBhaiya, our Guru and Inspiration ... from the day I started watching your videos ... problem solving has became easy and damn interesting :), Your Vlogs and Lifestyle are really nice and for us a threshold...pushing us to give our best... Lots of Best Wishes And More Success to you... . . . . . Date: Tera Saath (13/7) hai to...hume kya kami hai...dsa v ab hume asan lag rahi h XD XD XD
@nileshsinha78693 жыл бұрын
Great explanation..learned the concept of next smaller/greater 🔥
@devbhattacharya1532 жыл бұрын
Best explanation video ever!!!
@vm1662 Жыл бұрын
Thanks Striver for yet another amazing video!!! Just a question : Can another brute force approach be finding the area for each combination possible? Like so below: public int largestRectangleArea(int[] heights) { int maxArea = Integer.MIN_VALUE; for(int i = 0; i < heights.length; i++) { int min = heights[i]; for(int j = i; j < heights.length; j++) { min = Math.min(min, heights[j]); int area = min * (j-i+1); maxArea = Math.max(area, maxArea); } } return maxArea; }
@deepaksolanki19722 жыл бұрын
Best Explanation, Hats off to the efforts. Subscribed !!!
@sabbysays3 жыл бұрын
You are the best! Thanks for all the efforts :)
@tusharjolly27342 жыл бұрын
Best explanation!!!!
@jitengarg57403 жыл бұрын
it's good that u try explain each and every part but u can make it more shorter it saves time after all ek do vaar dry run karne se samaj to a he jata hai
@takeUforward3 жыл бұрын
Actually point is sb k lie h video. Bht log aise bhi hote h jinhe pura chye detailed. So for people who don’t want detailed they can fast forward na. But if i trim, then the other guys will not understand
@HarshGupta-wi1zn3 жыл бұрын
Getting runtime error segmentation fault error for the Same code in GFG. Expected time complexity : O(N) Expected Space complexity:O(N)
@004-u6f Жыл бұрын
same ,any idea how to correct it?
@anupam60452 жыл бұрын
Thanks striver for the wonderful explanation
@cinime2 жыл бұрын
Amazing explanation, thank you very much!!
@alamatel3 жыл бұрын
Thank you much for making this video.
@akashskumar993 жыл бұрын
superb explanation bruh
@bahubaljain30633 жыл бұрын
Just doing the same question.....and video aagyi 😂😂😂 ye mehaz itedaaq h ya khuda ka ishara🌸
@dsa_tutorial Жыл бұрын
we can also take 1 * 6 as 6 as height than also we will get rectangle whose area is maximum
@h.kchannel41152 жыл бұрын
Thank you for this great explanation!!!
@gopropro35443 жыл бұрын
Nicee T-Shirtt!!!!!
@newbienate2 жыл бұрын
Rider doing good. Thanks
@rydmerlin Жыл бұрын
Why in the second example did you exclude the the first bar ? 1x5=5 why isn’t it 1x6?
@dataman45033 жыл бұрын
Can we do this in a single traversal? There are solutions in Leetcode Discuss with 1 traversal, but could not understand.
@yashkhatwani3198 Жыл бұрын
Amazing
@KRajesh-ej7dy Жыл бұрын
Bro thanks for the video.I got total clarity after watching this.But the java code which u have given is not executing.
@ananyaa85972 жыл бұрын
Man this question is crazy
@StudyEmail-p9u10 ай бұрын
Thank You !!
@suryansh702 жыл бұрын
such a nice explaination
@lBaZeRl10 ай бұрын
Ain't no way nobody's talking about the fire shirt
@ashishpradhan62504 ай бұрын
understood, thanks
@ankitr29692 жыл бұрын
great explanation!
@123_shreyoshide92 жыл бұрын
GOD LEVEL! THANK YOU!
@kalebakeitshokile13662 жыл бұрын
what a great explanation!
@AnujSingh-ju4nr2 жыл бұрын
bhai itna stress mat diya karo, over ho jata hai kya ! heath ka dhyyan rakkho😄
@aj97063 жыл бұрын
Brilliant thanks
@abhinay.k3 ай бұрын
thank you
@shubhamrane29182 жыл бұрын
Thanks for the detailed explanation!!
@shubhamrane29182 жыл бұрын
Is there a playlist of the leetcode solutions on your channel?
@haidarmohammad8510 Жыл бұрын
Why are you concern about greater element in the stack? Please reply..........
@OrbitZyro8 ай бұрын
because a bigger histogram / building / block is something ith element can expand into, but it cannot expand into a smaller one
@dadidivya86632 жыл бұрын
Python Sol: class Solution: def largestRectangleArea(self, heights: List[int]) -> int: n = len(heights) li = [0 for i in range(n)] ri = [n-1 for i in range(n)] s1 = [0] s2 = [n-1] maxi = 0 for i in range(1,n): while(s1!=[] and heights[i]
@satyampande6842 жыл бұрын
understood!!
@aks-nc6kq2 жыл бұрын
Bro you look like munawar faruqui
@chitranshkumar66943 жыл бұрын
Thanks bhaiya for making this video
@yahoo-kids Жыл бұрын
oo bhaii maja aagya
@souravsarkar61072 жыл бұрын
understood sir
@shwetanksingh52082 жыл бұрын
//Brute force solution class Solution { public: int largestRectangleArea(vector& heights) { int ans = 0,n=heights.size(); for(int i=0;i=0 && heights[leftSmaller]>=heights[i]); ans = max(ans,(rightSmaller-leftSmaller-1)*heights[i]); } return ans; } };
@zeeshanhasankhan2 жыл бұрын
ans = max(ans,(rightSmaller-leftSmaller+1)*heights[i]);
@subashkannan949 Жыл бұрын
Indeed
@jitendrasinghsola2 жыл бұрын
the link in the description is pointing to the same video not part 2
@mihiragarwal12692 жыл бұрын
loved the video
@navyasri50772 жыл бұрын
height of instagram..lol .actually this indicates i am listening so carefully 😋
@anjaliyadav93602 жыл бұрын
Thanks!
@dreamyme5432 жыл бұрын
Understood
@harshitjaiswal94398 ай бұрын
understood
@jeevan999able Жыл бұрын
Man thank you !
@rubyshorts2819 ай бұрын
actual video starts at 8:46
@susantakumardutta62832 жыл бұрын
Understood🙂🙂
@COURATWENTYTHREE3 ай бұрын
understood❤❤❤
@vivekpawar3112 жыл бұрын
Understood!
@surbhijain88003 жыл бұрын
thank you very much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! indeed helpful
@abhisheksoni96442 жыл бұрын
can we solve this using doubly linked list?
@ayush.kumar.139073 жыл бұрын
nice tshirt
@khushil99887 ай бұрын
take a bow
@rachanasingh22312 жыл бұрын
awesome!!
@gowthamarun433 жыл бұрын
Super 💥💥
@kyakya64902 жыл бұрын
Liked it due to the tshirt lmao
@srinathv14129 ай бұрын
Understood !!!!!
@samdarshikumar64883 жыл бұрын
🔥🔥🔥🔥🔥🔥 best
@prashantbisht22193 жыл бұрын
Shouldn't it be O(n^2), since consider an non increasing order array, for right side, we will delete every element greater than current, hence for every element we have to traverse till very first, shouldn't that be n^2 ???????????
@takeUforward3 жыл бұрын
Every element is pushed once and popped out once. So ideally its 2n
@prashantbisht22193 жыл бұрын
@@takeUforward Yaaa I got it now, thanks dude, you even replied in your old videos, that's great..
@khushil99887 ай бұрын
why i am feeling like this is similar to trapping rain water