for(int i=0; i<nc; i++){ if(**nc-1 == i** || curSum+coins[i] < coins[i+1]){ curSum += coins[i]; res++; } } cout << res << endl; } whats the logic behing "nc-1 == i" thanks