Description
Solutions
Submission
Get Sequence Sum
🔥 FULLTIME

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 integers
  • Return

  • long: the value of the sequence sum
  • Example 1:

    Input:  i = 5, j = 9, k = 6
    Output: 56
    Explanation:

    Sum all the values from i to j and to k 5 + 6 + 7 + 8 + 9 + 8 + 7 + 6 = 56.

    Constraints:
    • -108 <= i, j, k <= 108
    • i, k <= j
    Testcase

    Result
    Case 1

    input:

    output: