Ad
  • Custom User Avatar
  • Custom User Avatar

    I corrected the method and it worked.
    I really didn't understand the description.
    Considering that I'm not the only one like that, I need to clarify the instructions a bit at this point.

  • Custom User Avatar

    I see that there are already threads with this question.
    But the instructions for this task are really misleading.

  • Custom User Avatar

    The array was: {-1, 1, 0, -1, 1, 0, -1, 1, 0, 0} - expected:<2> but was:<0>

    I found the array where I have problems.
    I think it is this array.

  • Custom User Avatar

    that's not a crash though is it, but wrong answer?
    presumably the last one
    also note that you have a return statement above where you print out an array, if that triggers you won't see that array which is the same situation as before

  • Custom User Avatar

    @natan -

    Is it possible to understand on which array exactly my method crashes?
    I printed all the arrays in the test group. However, looking with my eyes, I can't understand where I made a mistake, everything seems to be correct.

  • Custom User Avatar

    Thanks. Indeed, I forgot to remove 1 line of code.

  • Custom User Avatar

    that's not what the array was, that's what you printed. take greater care in what you print to see what the array was.

  • Custom User Avatar

    The array was: {16, 102, 21, 130, -20735, 7422, 88, 16, 8}: expected +0
    Why should there be 0 here? Can anyone explain?
    I have - expected:<0> but was:<-1> (java)

  • Custom User Avatar

    Yep, 0 is correct. When you target an index to then count to the left and right, the value stored on that index is left out meaning that at index 0, you ignore the 20 which leads to sums of 0 on both left and right.

  • Custom User Avatar

    I see where you found the 0 sum at index 0. That is just confusion. You won't get to 0 anymore if you don't count into the left and right sums the number at the target index.

    So, counting the -1 at index 0 which is incorrect gets you 0 to the left and 1 to the right.

    Index 2 is correct in the end.

  • Custom User Avatar

    don't use global variables (sum_left, sum_right); they keep their values between tests. (also, don't use arbitrarily size arrays like int sum_left[1000] as you do not know for sure that they will be large enough.)

  • Custom User Avatar
  • Custom User Avatar

    in this array, the sum to the left side of index 0 is 0, whereas the sum to the right side of index 0 is 1, so the two sides are unequal at index 0. please do not open issues to ask for help, ask a question instead

  • Custom User Avatar

    Hi, the test is correct. The result should be 2.

    [-1, 1, 0, -1, 1, 0, -1, 1, 0, 0] input data
    [ 0, 1, 2,  3, 4, 5,  6, 7, 8, 9] data index
    [-1,1] == 2 == [-1,1,0,-1,1,0,0] the sum of the numbers on the right and on the left are equal
    [] != 0 != [1,0,-1,1,0,-1,1,0,0] on the left sum to zero and on the right sum to 1
    
  • Loading more items...