Range Sum Query - Immutable

Easy

Description

Given an integer array nums, handle multiple queries sumRange(left, right) which returns the sum of elements between indices left and right inclusive.

Examples

Input:nums = [-2, 0, 3, -5, 2, -1], sumRange(0, 2)
Output:1
Explanation:

Sum of [-2, 0, 3] = 1.

Input:nums = [-2, 0, 3, -5, 2, -1], arg2 = 0, arg3 = 2
Output:1
Explanation:

Sum of elements from index 0 to 2: -2 + 0 + 3 = 1.

Input:nums = [-2, 0, 3, -5, 2, -1], arg2 = 2, arg3 = 5
Output:-1
Explanation:

Sum of elements from index 2 to 5: 3 + (-5) + 2 + (-1) = -1.

Constraints

  • 1 ≤ nums.length ≤ 10⁴
  • -10⁵ ≤ nums[i] ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!