Find the index which is the last to be reduced to zero after performing a given operation | Function that returns the index which will be the last to become zero after performing given operation ; Initialize the result ; Finding the ceil value of each index ; Finding the index with maximum ceil value ; Driver code
def findIndex ( a , n , k ) : NEW_LINE INDENT index = - 1 NEW_LINE max_ceil = - 10 ** 9 NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ i ] = ( a [ i ] + k - 1 ) // k NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] >= max_ceil ) : NEW_LINE INDENT max_ceil = a [ i ] NEW_LINE index = i NEW_LINE DEDENT DEDENT return index NEW_LINE DEDENT arr = [ 31 , 12 , 25 , 27 , 32 , 19 ] NEW_LINE K = 5 NEW_LINE N = len ( arr ) NEW_LINE print ( findIndex ( arr , N , K ) ) NEW_LINE