• + 1 comment

    Yeah, if we went with the brute force solution with two nested for loops, we will get a graph as below for the array if we used the data below

    arrayManipulation(40,[[19, 28, 419],
    [4, 23, 680],
    [5, 6, 907],
    [19, 33, 582],
    [5, 9, 880],
    [10, 13, 438],
    [21, 39, 294],
    [13, 18, 678],
    [12, 26, 528],
    [15, 30, 261],
    [8, 9, 48],
    [21, 23, 131],
    [20, 21, 7],
    [13, 40, 65],
    [13, 23, 901],
    [15, 15, 914],
    [14, 35, 704],
    [20, 39, 522],
    [10, 18, 379],
    [16, 27, 8],
    [25, 40, 536],
    [5, 9, 190],
    [17, 20, 809],
    [8, 20, 453],
    [22, 37, 298],
    [19, 37, 112],
    [2, 5, 186],
    [21, 29, 184],
    [23, 30, 625],
    [2, 8, 960]])
    

    but if we used the second method which is adding at the first index and subtracting at the index afer the last we get this graph

    and then we can get the maximum out of summing the results as below