Learn
Exam

Calculate the Sum within a Range

Difficulty
STARTER

Problem

Given two integers start and end, write a function solution that returns the sum of all integers from start to end (inclusive).


Constraints

  • start and end are integers between -100 and 100 inclusive.
  • start is less than or equal to end.

Test Case

Test Case Number start end return
1 1 10 55
2 -3 3 0
3 5 5 5

Explanation for Test Case 1

  • When start = 1 and end = 10, the sum of all integers from 1 to 10 is 1 + 2 + 3 + ... + 10 = 55.

Explanation for Test Case 2

  • When start = -3 and end = 3, the sum of all integers from -3 to 3 is (-3) + (-2) + (-1) + 0 + 1 + 2 + 3 = 0.

Explanation for Test Case 3

  • When start = 5 and end = 5, the sum of all integers from 5 to 5 is just 5.