Find the index with minimum score from a given array | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void Min_Score_Index ( int N , vector < int > A ) { vector < int > Score ( N , 0 ) ; 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 = INT_MAX ; for ( int i : Score ) min_value = min ( i , min_value ) ; int ind = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( Score [ i ] == min_value ) ind = i ; } cout << ( ind ) ; } int main ( ) { int N = 5 ; vector < int > A = { 1 , 2 , 3 , 4 , 5 } ; Min_Score_Index ( N , A ) ; }