To find number of events occuring at a given point affected by multiple ranges.
Problems
370. Range Addition
- https://leetcode.com/problems/range-addition
- When event starts increase the value at the start position
- When it ends decrease the value at the end position
starts = defaultdict(int)
ends = defaultdict(int)
for s, e, inc in updates:
starts[s] += inc
ends[e] += inc
inc = 0
res = []
for i in range(length):
inc += starts[i]
res.append(inc)
inc -= ends[i]
return res