Back/Custom Sort: Range Sum

Custom Sort: Range Sum

EasyLevel: 6Topic: Sorting and Searching
XP Reward:+50 XPCoin Reward:+5 Coins

You are given an array and one inclusive 1-indexed range. Compute the sum of the values inside that range.

This problem is part of Sorting and Searching practice and is designed to strengthen the Custom Sort pattern.

Input Format

  • The first line contains an integer n, the number of values.
  • The second line contains n space-separated integers.
  • The third line contains two integers l and r, the inclusive 1-indexed range.

Output Format

Return one integer: the sum of values from index l through index r.

Example 1

Input:

6
-14 3 20 37 54 -26
3 5

Output:

111

Explanation:

  • The requested range is from position 3 to 5.
  • The selected values are 20, 37, 54, and their sum is 111.

Constraints

  • 1 <= n <= 10^5
  • 1 <= l <= r <= n
  • -10^9 <= value <= 10^9

Return Requirement

Implement the starter function for this Easy problem. Read from the raw input string and return only the required answer, with no labels or debug text.

Judge Behavior

Run Code checks the visible sample cases. Submit checks those samples plus additional hidden cases that follow the same input format and constraints.

Loading editor...
Input
6
-14 3 20 37 54 -26
3 5
Expected Output
111