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
function getPosition ( a , n , m ) { for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = ( a [ i ] / m + ( a [ i ] % m ) ) ; } let ans = - 1 , max = - 1 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( max < a [ i ] ) { max = a [ i ] ; ans = i ; } } return ans + 1 ; } let a = [ 2 , 5 , 4 ] ; let n = a . length ; let m = 2 ; document . write ( getPosition ( a , n , m ) ) ;