Find the index with minimum score from a given array | Java program for the above approach ; Function to find the index with minimum score ; Stores the score of current index ; Traverse the array in reverse ; Update minimum score ; Print the index with minimum score ; Driver Code
import java . util . * ; class GFG { static void Min_Score_Index ( int N , int [ ] A ) { int [ ] Score = new int [ N ] ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( A [ i ] + i < N ) Score [ i ] = A [ i ] * Score [ A [ i ] + i ] ; else Score [ i ] = A [ i ] ; } int min_value = Integer . MAX_VALUE ; for ( int i : Score ) min_value = Math . min ( i , min_value ) ; int ind = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( Score [ i ] == min_value ) ind = i ; } System . out . print ( ind ) ; } public static void main ( String [ ] args ) { int N = 5 ; int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; Min_Score_Index ( N , A ) ; } }