Heights: . Maintain increasing stack of indices. , h=: push . Stack:
, h=: , pop . Area = .
Push . Stack:
, h=: push . Stack:
, h=: push . Stack:
, h=: pop , area = .
Pop , area = . Push . Stack:
, h=: push . Stack:
Pop remaining: areas . Maximum: .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Trace the algorithm
Heights: . Maintain increasing stack of indices. , h=: push . Stack:
, h=: , pop . Area = .
Push . Stack:
, h=: push . Stack:
, h=: push . Stack:
, h=: pop , area = .
Pop , area = . Push . Stack:
, h=: push . Stack:
Pop remaining: areas . Maximum: .