Find the index with minimum score from a given array | 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
function Min_Score_Index ( N , A ) { var Score = Array ( N ) . fill ( 0 ) ; for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( A [ i ] + i < N ) Score [ i ] = A [ i ] * Score [ A [ i ] + i ] ; else Score [ i ] = A [ i ] ; } var min_value = 1000000000 ; Score . forEach ( i => { min_value = Math . min ( i , min_value ) ; } ) ; var ind = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( Score [ i ] == min_value ) ind = i ; } document . write ( ind ) ; } var N = 5 ; var A = [ 1 , 2 , 3 , 4 , 5 ] ; Min_Score_Index ( N , A ) ;