Explanation for this solution


  • -1
    S

    The idea of this solution is that the max area should start at one point.
    So basically every number will stay in stack at some point.

    The point is, when the area starting from a bar at position i is calculated is, when we encounter a bar of shorter height than i. Until then, it stacks all the (taller) bars.

    As for the time complexity, it is O(n) as it iterate through the list only once and the values stacked are visited only once.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.