There is a O(n) solution but with O(n) space using stack.
Idea is the same for the problem of finding rectangle of 1's in a matrix 
with a max area.

So for each bar of height H we should know nearest index M of the bar to the 
left with height < H,
and the same to the right hand side - index N. Area = (M - N - 1) * H.

But how to do it in O(1) space?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to