Leaders in an array | PHP Function to print leaders in an array ; Rightmost element is always leader ; Driver Code
< ? php function printLeaders ( & $ arr , $ size ) { $ max_from_right = $ arr [ $ size - 1 ] ; 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 ( " ▁ " ) ; } } } $ arr = array ( 16 , 17 , 4 , 3 , 5 , 2 ) ; $ n = sizeof ( $ arr ) ; printLeaders ( $ arr , $ n ) ; ? >