Dsa
Arrays
Medium
Subarray with Sum Equals K
Given an integer array and an integer K, find the number of continuous subarrays whose sum equals to K. The input consists of a single line with space-separated integers for the array followed by the integer K. The output should be a single integer, the count of subarrays.
Example:
Input: 1 1 1 2
3
Output: 2
Explanation: The continuous subarrays that sum to 3 are [1, 1, 1] and [1, 2].
Key concepts
arrayssubarrayhash-mapprefix-sum
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now