PythiloLesson 2 of 8 · progress kept in this browser

Apply many range updates with differences

A difference table records where a change starts and where it ends. Instead of touching every cell in every range, add a delta at the left boundary and undo it at the right boundary. One final running sum reconstructs every cell. This is useful when all updates arrive before any answers are needed.

difference = [0, 4, 0, -4]
current = 0
for delta in difference:
    current += delta
    print(current)
Your task

Write apply_updates(n, updates). Begin with n zeros. For each (left, right, delta), add delta to indices in [left, right). Bounds are valid. Return the final list, including overlapping and negative updates.