Description
Solutions
Get Sequence Sum
🔥 FULLTIME📚RELATED PROBLEMS
Given three integers, i, j, and k
, a sequence sum to be the value of
i + (i + 1) + (i + 2) + (i + 3) + ... + (j - 2) + (j - 3) + ... + k
(incremnt from i
until it equals j
, then decrement from
j
until it equals k
). Given values i
, j
,
and k
, calculate the sequence sum as described.
Function Description
Complete the function getSequenceSum
in the editor.
getSequenceSum
has the following parameter(s):
int i, int j, int k
: three integersReturn
long
: the value of the sequence sumExample 1:
Input: i = 5, j = 9, k = 6
Output: 56
Explanation:Sum all the values from
i
toj
and tok
5 + 6 + 7 + 8 + 9 + 8 + 7 + 6 = 56.
Constraints:
-108 <= i, j, k <= 108
i, k <= j
Related Problems
Testcase
Result
Case 1
input:
output: