30: Subarrays of sum K

Given an array of integers and an integer k, you need to find the number of subarrays whose sum equals to k

 

Example 1

Input: array = [1, 2, 3], k = 3

Output: 2

Explanation: [1, 2] - first subarray, [3] - second subarray

Example 2

Input: array = [2, 2, 3], k = 5

Output: 1

Explanation: [2, 3] subarray