01 · Question
Given an integer array and updates (left,right,delta), add delta to every index in the half-open interval [left,right). Return the final array without modifying the input. All updates satisfy 0 <= left <= right <= n; empty ranges are allowed. Values and accumulated sums fit signed 64-bit integers.
Example: nums=[1,2,3], updates=[(0,2,4),(1,3,-1)] returns [5,5,2].
02 · Analysis
Record +delta at left and -delta at right in an n+1 difference array. A prefix scan carries each contribution through exactly its intended interval; the extra slot handles right=n. Add the running increment to each original value. Empty updates cancel at the same index. With q updates, time O(n+q), auxiliary space O(n), output space O(n). This batching requires no intermediate queries.