Find the position of the last removed element from the array | Function to find the original position of the element which will be removed last ; take ceil of every number ; Since position is index + 1 ; Driver code
< ? php function getPosition ( $ a , $ n , $ m ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ a [ $ i ] = ( $ a [ $ i ] / $ m + ( $ a [ $ i ] % $ m != 0 ) ) ; } $ ans = -1 ; $ max = -1 ; for ( $ i = $ n - 1 ; $ i >= 0 ; $ i -- ) { if ( $ max < $ a [ $ i ] ) { $ max = $ a [ $ i ] ; $ ans = $ i ; } } return $ ans + 1 ; } $ a = array ( 2 , 5 , 4 ) ; $ n = sizeof ( $ a ) ; $ m = 2 ; echo getPosition ( $ a , $ n , $ m ) ; ? >