 Subarrays with sum K
Medium Accuracy: 61.59% Submissions: 8388 Points: 4

Given an unsorted array of integers, find the number of continuous subarrays having sum exactly equal to a given number k.

Example 1:

Input:
N = 5
Arr = {10 , 2, -2, -20, 10}
k = -10
Output: 3
Explaination:
Subarrays: arr[0...3], arr[1...4], arr[3..4]
have sum exactly equal to -10.

Example 2:

Input:
N = 6
Arr = {9, 4, 20, 3, 10, 5}
k = 33
Output: 2
Explaination:
Subarrays : arr[0...2], arr[2...4] have sum
exactly equal to 33.

You don't need to read input or print anything. Your task is to complete the function findSubArraySum() which takes the array Arr[] and its size N and as input parameters and returns the count of subarrays.

Expected Time Complexity: O(NlogN)
Expected Auxiliary Space: O(N)

Constraints:
1 ≤ N ≤ 2*104
-103 ≤ Arr[i] ≤ 103
-107 ≤ k ≤ 107

We are replacing the old Disqus forum with the new Discussions section given below.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  