Loading Now

findRange

Given the array of positive integers and the integer n, find whether there is a range of length at least 1, sum of the array’s elements in which is equal to the given number.

Example:

  • For arr = [1,2,3,4,5] and n = 7 the output should be findRange(arr, n) = true.
    Since the sum of the elements in range [2, 3] is array([2, 3]) = [3,4] and 3+4=7

Input/Output:

  • [execution time limit] 0.5 seconds

  • [input] array.integer array

    0 ≤ |array| ≤ 2000.

  • [input] integer n

  • [output] boolean

    true if such a range exists, false otherwise.

Post Comment

Contact