ByteByteGo logo
menuProblems List

Sum Between Range

Easy

Given an integer array, write a function which returns the sum of values between two indexes.

Example:

Input: nums = [3, -7, 6, 0, -2, 5],
       [sum_range(0, 3), sum_range(2, 4), sum_range(2, 2)]
Output: [2, 4, 6]

Constraints:

  • nums contains at least one element.

  • Each sum_range operation will query a valid range of the input array.

You can practice coding exercises online by logging into bytebytego.com on your laptop.