Ad
  • Default User Avatar

    Hi @Jchristian297 - for this kata, if you specify an index i, then the "left sum" is all elements to the left of i not including i itself and similarly for the "right sum" is all elements to the right of i not including i itself

    So let's look at [5,6,444,2,7,2]:

      idx 0  1   2   3  4  5
         [5, 6, 444, 2, 7, 2]
          [---]  X    [----]
    

    In the above illustration, the answer is index 2 because to the left we have 5+6 = 11 and to the right we have 2+7+2 = 11. NOTE WE DON'T INCLUDE 444 in either sum.

    For your test case [10,-80,10,10,15,35,20], if you say index 0, then the sum to the left of element 10 is 0 and the sum to the right is -80 + 10 + 10 + 15 + 35 + 20 = 10 != 0.

    The correct answer here is index 6 because, to the left of index 6 we have: 10,-80,10,10,15,35 (note how we don't include 20) and to the right of index 6 we have 0. And 10 -80 + 10 + 10 + 15 + 35 = 0 as required.