A shot at an O(nlgn) algorithm.

Do a sweep line from top to bottom. Only look at the events when a new bar
is introduced (this is accomplished by sorting the bars based on height).

When a new bar arises, if there exist values immediately to the left and
right of the bar just merge them into a new sum.

This algorithm takes O(nlgn)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to