Skip to main content
LeetCode 370, Medium. Topics: Array, Prefix Sum. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

You are given an integer length and an array updates where updates[i] = [startIdx_i, endIdx_i, inc_i]. You have an array arr of length length with all zeros, and you have some operation to apply on arr. In the i^th operation, you should increment all the elements arr[startIdx_i], arr[startIdx_i + 1], ..., arr[endIdx_i] by inc_i. Return arr after applying all the updates.

Examples

Example 1

Constraints

  • 1 <= length <= 10^5
  • 0 <= updates.length <= 10^4
  • 0 <= startIdx_i <= endIdx_i < length
  • -1000 <= inc_i <= 1000

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026