Problem Statement
Definition
- Class:
- SumK
- Method:
- count
- Parameters:
- int, int[]
- Returns:
- int
- Method signature:
- int count(int k, int[] values)
- (be sure your method is public)
Notes
- If a value is repeated, count it each time it appears if it is a sum of k.
- Values may be negative or zero, but k will be positive.
Constraints
- k is between 1 and 1,000,000,000 (inclusive)
- each element in values is between -1,000,000,000 and 1,000,000,000 (inclusive)
- the number of elements in values is between 0 and 50 (inclusive)
Examples
3
{-987,5,0}
Returns: 2
-987 = -330 + -329 + -328, 5 is not the sum of 3 consecutive values, 0 = -1 + 0 + 1
1000
{0,-500,499500,499501,17,-500}
Returns: 3
-500 + -499 + ... + 499 = -500, 0 + 1 + ... + 999 = 499500, and neither 499501 nor 17 nor 0 can be expressed as the sum of 1000 consecutive values. (-500 is counted twice since it appears twice in values.)
1
{3,4,5,-1000000000}
Returns: 4
Each value is the sum of itself
2
{}
Returns: 0
2
{-999999999}
Returns: 1
1
{-9,-1,0,1,2,999999999}
Returns: 6
2
{-999999999,0,0,77,77,77,78,78,78,78}
Returns: 4
3
{622,623,623,624,624,624,-625,-625,-625,-625}
Returns: 3
3
{0,-1,-1,345,345,345,346,346,346,346,347,347,347,347,347}
Returns: 4
911911911
{0,0,0,0,1,1,911911911,911911911,911911911,911911912}
Returns: 7
1000000000
{-500000000,-1000000000,-1000000000,999999999,999999999,999999999}
Returns: 1
4
{4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}
Returns: 0
3
{-987,5,0}
Returns: 2
1000
{0,-500,499500,499501,17,-500}
Returns: 3
1
{3,4,5,-1000000000}
Returns: 4
2
{}
Returns: 0
999999999
{1}
Returns: 0