• + 3 comments

    I understand your logic but your method doesn't make any sense.

    Given the sample question:

    a b k
    1 5 3
    4 8 7
    6 9 1
    

    The resulting transformations to the array are

     1  2  3  4  5   6  7  8   9  10
    [0, 0, 0, 0, 0,  0, 0, 0,  0, 0]
    [3, 0, 0, 0, 0, -3, 0, 0,  0, 0] // a: 1, b: 5, k: 3, so b+1 = 6
    [3, 0, 0, 7, 0, -3, 0, 0, -7, 0]// a: 4: , b: 8, k: 7, so b+1 = 9
    [3, 0, 0, 7, 0, -2, 0, 0, -7, -1] // a: 6, b: 9, k: 1, so b+1 = 10
    

    It's not clear to me from this array how to calculate the accumulated slope. Obviously the answer is 10, and I can see a few ways you add various elements of this array together to get that, but it's not obvious to me how you do that. Do you add every single pair together and find the max?