Find the index which is the last to be reduced to zero after performing a given operation | Java implementation of the approach ; 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
import java . io . * ; class GFG { static int findIndex ( int [ ] a , int n , int k ) { int index = - 1 , max_ceil = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = ( a [ i ] + k - 1 ) / k ; } for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= max_ceil ) { max_ceil = a [ i ] ; index = i ; } } return index ; } static public void main ( String [ ] args ) { int [ ] arr = { 31 , 12 , 25 , 27 , 32 , 19 } ; int K = 5 ; int N = arr . length ; System . out . print ( findIndex ( arr , N , K ) ) ; } }