Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5594
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3412
Subarrays with sum K
Medium Accuracy: 70.02% Submissions: 992 Points: 4

Given an unsorted array of integers, find the number of 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