We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
slightly more understandable variation of the solution (in python)
arr = [0] * (n + 1)
for query in queries:
# where a represents the lower bound of the range,
# and b represents the upper bound.
a, b, k = query
arr[a] += k
try:
arr[b+1] -= k
except IndexError:
pass
max_val = running_sum = 0
for delta in arr:
# delta can be either positive or negative,
# but in any case it is added to the running sum.
# however max_val always contains the greatest sum so far
running_sum += delta
if max_val < running_sum:
max_val = running_sum
return max_val
Cookie support is required to access HackerRank
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 →
slightly more understandable variation of the solution (in python)