Count Subarray Sum Equals K

Hard Problems: N-Sum & Hashing DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Count total number of subarrays with sum equal to k, Subarray, Prefix Sum, Hashing, Map, Loops, Time Complexity, Space Complexity, complexity analysis, brute force, subarray, prefix sum, hash map.

Problem Statement: Given an array of integers and an integer k, return the total number of subarrays whose sum equals k. A subarray is a contiguous non empty sequence of elements within an array. Examples Example 1: Input Format: N = 4, array[] = {3, 1, 2, 4}, k = 6 Result: 2 Explanation: The subarrays that sum up to 6 are [3, 1, 2] and [2, 4]. Example 2: Input Format: N = 3, array[] = {1,2,3}, k = 3 Result: 2 Explanation: The subarrays that sum up to 3 are [1, 2], and [3].