Minimum index i such that all the elements from index i to given index are equal | Function to return the minimum required index ; Start from arr [ pos - 1 ] ; All elements are equal from arr [ i + 1 ] to arr [ pos ] ; Driver code ; Function Call
< ? php function minIndex ( $ arr , $ n , $ pos ) { $ num = $ arr [ $ pos ] ; $ i = $ pos - 1 ; while ( $ i >= 0 ) { if ( $ arr [ $ i ] != $ num ) break ; $ i -- ; } return $ i + 1 ; } $ arr = array ( 2 , 1 , 1 , 1 , 5 , 2 ) ; $ n = sizeof ( $ arr ) ; $ pos = 4 ; echo minIndex ( $ arr , $ n , $ pos ) ; ? >