I’m thinking to solve this problem by sorting the input array , that way multiply the height with adjacent number of same height parameters .
Please shed some light if some other way is possible.
Regarding Histogram Problem
You cannot solve this problem by sorting the input array as that would change the original histogram. You need to find the maximum area histogram in the given array only, so you are not allowed to modify it. I’ll give you some hints, then you should try to think of an approach. If you’re still not able to solve then let me know, I’ll give more hints.
- use a stack
- For every bar ‘x’, we calculate the area with ‘x’ as the smallest bar in the rectangle. What if we calculate such area for every bar ‘x’ and find the maximum of all areas.
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.