You are viewing a single comment's thread. Return to all comments →
Thank you. This is clear.
You could also find the max using: max(accumulate(my_array))
max(accumulate(my_array))
See below:
def arrayManipulation(n, queries): # initialise list arr = [0] * (n + 1) # update for a, b, k in queries: arr[a - 1] += k arr[b] -= k # accumulate values return max(accumulate(arr))
However, I have not understood the theory behind the difference array algorithm, why it works the way it works and how to derive it.
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
Thank you. This is clear.
You could also find the max using:
max(accumulate(my_array))
See below:
However, I have not understood the theory behind the difference array algorithm, why it works the way it works and how to derive it.