Largest Rectangle in Histogram 🔥 | Stack Data structure & Algorithms Hello World Leetcode #84
Vložit
- čas přidán 10. 03. 2022
- This is the video under the series of DATA STRUCTURE & ALGORITHM in a STACK Playlist. Now we are going to solve a stack problem Largest Rectangle in Histogram Leetcode or Largest Rectangular Area in a Histogram
Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
complete DSA preparation: github.com/Prince-1501/Comple...
----------------------------------------------------------------------------------------
► 84. Largest Rectangle in Histogram
Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.
Input: heights = [2,1,5,6,2,3]
Output: 10
Explanation: The above is a histogram where the width of each bar is 1.
The largest rectangle is shown in the red area, which has an area = of 10 units.
►Largest Rectangle in Histogram: leetcode.com/problems/largest...
► Code In this video: github.com/Prince-1501/Hello_...
► Pdf In this video: github.com/Prince-1501/Hello_...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
Telegram► telegram.me/helloworldbyprince
----------------------------------------------------------------------------------------
►Our Playlists on:-
► Tree: • Tree Data Structure & ...
► Stack: • Stack & Queue Data Str...
► Hashing: • Hashing Data Structure...
► Graph: • Graph Data Structure &...
► Matrix: • Matrix (Multidimension...
► STL: • Standard Template Libr...
► Leetcode: • LeetCode Solutions And...
►Competitive Programming: • Full course in Competi...
►C++ Full Course : • C++ full Course in HINDI
►Algorithms: • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
✨ Tags ✨
leetcode problems
leetcode problems java
leetcode problems python
leetcode problems that got me tired
leetcode problems c++
leetcode problems and solutions python
leetcode problems playlist
leetcode problems and solutions java
leetcode problems in Hindi
leetcode problems javascript
leetcode problems and solutions
leetcode problems of the day
leetcode problems for beginners
leetcode problems easy
leetcode problems js
stack practice problems
stack practice problems gfg
leetcode stack questions
leetcode stack queue
stack hello world
Largest Rectangle in Histogram leetcode solution
Largest Rectangle in Histogram gfg
Largest Rectangle in Histogram
question asked in Google
off-campus placement
Online Stock Span
Practice stack data structure
Stack in a data structure in Hindi
Stack Full playlist for Beginners
algorithms
graph DSA
data structure
sorting algorithms
time-complexity analysis
gate computer science preparation
programming languages
#stack #Leetcode #programming
Sir just now fnshd viewing all ur stack videos thank you soo much
1. For providing que in description and code link in leetcode and gfg(helps to practice ques multiple times and understand the twist)
2. For pdf as well as code(it is very helpful when i watch in 240p coz my internet amount is less)
3. More than anything thank you from the core of my heart really really really
for starting the video by saying that ques is very easy and
insisting that we first try to solve it and stopping in middle of vdeo and telling us to try the further part
This implies for ur tree and grap playlist also as a newbie to CP i was intimidated on seeing all the complex content in yt and problems in website.
But after knowing abt this channel in yt recommendation i feel that this was really a boon to me.
All ur playlist Start frm scratch utterly which is very helpful
My only request to u is that pls if possible try to make some different playlists too like dynamic prgming and other topics which u feel impo to be Known.
When u teach i feel as if u teach straight frm ur heart genuinely pls continue this good work means a lot 🙏
Thanks 🙏
3:00 ❤ key point
Apke video dekhne ke baad doubt ho aisa nhi hua abbhi tak.
Thank you for those valuable videos and do cover more leetcode solutions which are importan. Thank you
Greatt workk..Your explanation is soo good
amazing explanation .
Nice !!
You are the best
Amazing explanation,loved it!!
Thanks buddy
Nice aise pdhaya karo har question sir naive to optimise. Best 👍😂👍
Ekdum bhai ❤️
GREAT WORK, THANKS SO MUCH...
Glad you liked it!
Thanks Bhaiya, this video was really helpful, I solved the question in O(N) when you said "Do It Yourself".
Great 👍
This video quality is soo good. please consistency maintain this.
sure brother i will sure
bhaiya I have a doubt about how to find the time complexity of this code could you explain it?
Gotcha greate Explaintion.
Try to upload daily atleast 1 video if possible
Sure i will try my best
Nice explanation sir
Keep learning buddy 🤠
Amazing explanation 🥺
bass aise hi padte raho
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
thx
your welcome
maja hi aagaya es question par , time laga but aacha question tha
🔥🔥
amazing one
Thank you! Cheers!
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
How can we find for a largest square in a histogram? What changes can we make?
Nice question ✅
Consider every bar as small
Now, count the number of bars ...which can make form rectangle
Now, check if
count of bar >= height of bar
Then a square can be formed ...
Then area = height * height
Nice sir
Keep learning and thanks for the support 🙂
jabardast explanation! mza aa gya🤩🤩🤩🤩
Thanks aniket
why this problem feels like container with most water on gfg .
Osm BHAIYA 🫂🙏
Thanks buddy
Hi, Subhankar. I have 6 years of experience in TCS. Is it possible to move to product based company. Will they consider my profile
Offcourse it is possible and they will definitely consider your profile
@@HelloWorldbyprince❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤q❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
i have written the same code and its working also but after submitting its showing TLE when all values are same please help
my code
class Solution {
public:
vector right_min(vector& h)
{
vector ans2;
stack st;
int n=h.size();
for(int i=n-1;i>=0;i--)
{
while(!st.empty() && h[st.top()]>=h[i])
st.pop();
int res=(st.empty()) ? n:st.top();
ans2.push_back(res);
st.push(i);
}
reverse(ans2.begin(),ans2.end());
return ans2;
}
vector left_min(vector& h)
{
vector ans1;
stack st;
int n=h.size();
for(int i=0;i=h[i])
st.pop();
int res=st.empty() ? -1:st.top();
ans1.push_back(res);
st.push(i);
}
return ans1;
}
int largestRectangleArea(vector& h) {
int maxi=-1;
vector ans1=left_min(h);
vector ans2=right_min(h);
for(int i=0;i
Bhaiya please make a video on your resume please 🙏
Exactly kya cahhaiye resume wali video me
@@HelloWorldbyprince apne resume me kya achivement add ki thi project kese explain Kiya tha format konsa tha , agar sirf Leetcode Kiya hai to achivement kya likhe iss se releted
class Solution {
public int largestRectangleArea(int[] heights) {
int n=heights.length;
Stackst=new Stack();
int[] ps=new int[n];
int[] ns=new int[n];
for(int i=0;i=heights[i]){
st.pop();
}
if(st.isEmpty()){
ps[i]=-1;
}else{
ps[i]=st.peek();
}
st.push(i);
}
while(!st.isEmpty()){
st.pop();
}
for(int i=n-1;i>=0;i--){
while(!st.isEmpty()&&heights[st.peek()]>=heights[i]){
st.pop();
}
if(st.isEmpty()){
ns[i]=n;
}else{
ns[i]=st.peek();
}
st.push(i);
}
int max=0;
for(int i=0;i
sir i think in naive approach curr+=arr[i] ki jagah cur+=cur; ayeegaa.....
int get_max_area(vector a)
{
stack st;
int n = a.size(),ans=0,i=0;
a.push_back(0);
while(ia[i])
{
int h = a[st.top()];
st.pop();
if(st.empty())
{
ans = max(ans,h*i);
}
else
{
int len = i-st.top()-1;
ans = max(ans,h*len);
}
}
st.push(i);
i++;
}
return ans;
}
waoo keep going to
My Approach :
class Solution {
public:
int largestRectangleArea(vector& heights) {
/* BRUTE FORCE : O(N*N) using array data structure only and for loop
int n=heights.size();
vector pre(n,-1),post(n,-1);
//finding pre
for(int i=n-1;i>=0;i--)
{
bool check=false;
for(int j=i-1;j>=0;j--)
{
if(heights[i]>heights[j])
{
pre[i]=j;
check=true;
break;
}
}
if(check==true)
check=false;
}
//finding post
for(int i=0;i
Amazing work buddy, keep it up