
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]
andn = 7
the output should befindRange(arr, n) = true.
Since the sum of the elements in range[2, 3]
isarray([2, 3]) = [3,4]
and3+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