Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given an integer array 'arr' of size 'N' and an integer 'K'.

Your task is to find the total number of subarrays of the given array whose sum of elements is equal to k.

A subarray is defined as a contiguous block of elements in the array.

```
Input: ‘N’ = 4, ‘arr’ = [3, 1, 2, 4], 'K' = 6
Output: 2
Explanation: The subarrays that sum up to '6' are: [3, 1, 2], and [2, 4].
```

Detailed explanation

```
2
4 6
3 1 2 4
3 3
1 2 3
```

```
2
2
```

```
Test Case 1:
Input: ‘N’ = 4, ‘arr’ = [3, 1, 2, 4], 'K' = 6
Output: 2
Explanation: The subarrays that sum up to '6' are: [3, 1, 2], and [2, 4].
Test Case 2:
Input: ‘N’ = 3, ‘arr’ = [1, 2, 3], 'K' = 3
Output: 2
Explanation: The subarrays that sum up to '7' are: [1, 2], and [3].
```

```
2
3 7
1 2 3
4 9
6 3 5 2
```

```
0
1
```