Please help me identify the mistake in my code.
Area under histogram
hi… ur approach doesn’t seem to be correct… refer my code https://ide.codingblocks.com/s/606864
My intuition is:
-Traverse through all the bars one by one.
-If current bar is not obstacle for previous bar, then push() current bar’s index into stack.
-While current bar is obstacle for previous bar(i.e. for bar corresponding to s.top()), then pop() previous bar and calculate area due to previous bar.
(I am storing area corresponding to each bar in an array)
If we traversed through all the bars, then check if stack is empty or not. If stack is not empty, then calculate area due to those bars(in the same manner calculated before).
I hope i am clear. If not please do tell. I will try to explain again.
I just want to know where is my logic wrong.
basically for every block u have to find at what max left and right u can consider to find max ans
i hope ur doubt is cleared… if still some doubt is there i suggest u to watch the video lecture on the same available in course contents…
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.