Rightmost element is always leader
echo ( $ max_from_right ) ; echo ( " ▁ " ) ; for ( $ i = $ size - 2 ; $ i >= 0 ; $ i -- ) { if ( $ max_from_right < $ arr [ $ i ] ) { $ max_from_right = $ arr [ $ i ] ; echo ( $ max_from_right ) ; echo ( " ▁ " ) ; } } }