Ad
  • Default User Avatar

    I have an issue in c++ code, in this test
    vector numbers { 1,100,50,-51,1,1 };

    In my IDE output is: 1, but in code wars i have output -1.

    This is my code

    int find_even_index (const std::vector numbers) {
    int sum_r = 0;
    int sum_l = 0;
    for(int i = 0; i < numbers.size(); i++){
    for (int l = 0; l < i; l++) {
    sum_l += numbers[l];
    }
    for (long int r = numbers.size(); r > i; r--) {
    sum_r += numbers[r];
    }
    if (sum_l == sum_r) {
    return i;
    } else sum_l = 0; sum_r = 0;
    }
    return -1;
    }

    Please help me find out what is the problem