Dsa
Prefix Sum
Medium
K-Element Sum Ranges
You are given an array of integers and a value K. Your task is to find the total count of unique subarrays whose sum equals K. You must implement an efficient solution using prefix sums to avoid recalculating sums.
Input:
- The first line contains integers n (1 ≤ n ≤ 100,000) and K (1 ≤ K ≤ 1,000,000).
- The second line contains n integers a[i] (−10000 ≤ a[i] ≤ 10000) representing the elements of the array.
Output:
- Output a single integer, the count of unique subarrays that sum up to K.
Example:
Input:
5 5
1 2 3 -2 4
Output:
2
Key concepts
prefix_sumarray
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