Ad
  • Default User Avatar

    Thanks so much! I understood my mistake and my solution is correct now! Finally I did it!

  • Custom User Avatar

    Your solution fails following tes cases:

    a=50095301248058391139327916261
    b=81055900096023504197206408605
    
    a=6144617321112760
    b=4344202181817737
    
  • Default User Avatar

    (Java) Hello! I have unpassed test here: "Index 29 out of bounds for length 29". I don't what does it mean and what i have to change. But in IntelliJ Idea my code works every time with any numbers, actually i took numbers with different length. Can someone tell what about this test?

  • Default User Avatar

    my first question:
    sorry, i was meaning how can i define maximum sum if i even don't know what does our array consist of(certain numbers)? And smoothly moving on to the second question we don't know about sum of our subarray and accordingly about length of our subarray. So how can i figure out sum if i don't know number of values my subarray? As i understand we can find out sum if we know number of values of subarray(this is standart algorithm), but we dont't know that.

  • Default User Avatar

    Yes, once you understand the objective of the kata, you have to come up with an algorithm/program that finds the result yourself!

    As always, if you are a bit confused, it is a good idea to try with the given example and use a pen and paper (old school) before trying to write code - how would you solve this kata on paper in "English/words".

    For your 2nd question, I don't understand 100% - the "length of the optimum subarray" can range from 0 to L (where L is the size of the input) - for example:

    [-3,-6,-1] -> for this given input, the correct answer for the maximum subarray sum is 0; this occurs when you take the empty subarray [] with no elements in it (any other subarray would contain a negative number so it would be less than 0)

    [5,9,100,5,2] -> for this given input, the correct answer for the maximum subarray sum is 5+9+100+5+2=121, when you take the entire array of length 5.

  • Default User Avatar

    ok, almost full part of task i understood. But how can i find out maximum sum? I have to come up with myself? And how have i to define length of subarray initially?

  • Default User Avatar

    Hi - you have to find the maximum sum you can make from the given array, by selecting a contiguous (this means, "all side by side in the original array") subarray.

    For example:

    # Good example from description:
    [-2, 1, -3,     4, -1, 2, 1,    -5, 4]
    # should be 6: [4, -1, 2, 1] <---- note how this subarray IS CONTIGUOUS in the original input array
    
    # Bad example:
    [-2, 1, -3, 4, -1, 2, 1, -5, 4]
    #    ^______^______^__^______^  
    # these sum to 1+4+2+1+4 =12 BUT THE NUMBERS ARE NOT SIDE BY SIDE in original array
    # therefore this is NOT allowed
    
  • Default User Avatar

    Can someone tell me what i have to do exactly? I can't figure out which subarray sum i need to calculate.