Subarray Sum Equals K
Practice this coding question on Coding Gurukul.
Problem statement
An energy meter records signed changes. Count how many nonempty consecutive reporting windows have a total exactly equal to a given target k. Windows with different start or end positions count separately, even when their values match.
Input format
First line: n k. Second line: n integers.
Output format
Print the number of matching windows.
Constraints
1 <= n <= 100000; -10000 <= value <= 10000; -1000000000 <= k <= 1000000000; use 64-bit counts.
Sample input
5 3 1 2 1 2 3
Sample output
4
Sign in to run or submit a solution in C++, Java or Python.