Dsa
Sliding Window
Medium
Substrings with Fixed Sum
Given an array of integers and a target sum, find the number of contiguous subarrays whose elements sum to the target.
Input Format:
- The first line includes the target sum (integer).
- The second line is an array of integers (space-separated).
Output Format:
- An integer representing the number of contiguous subarrays that sum to the target.
Example:
Input:
5
1 2 3 4 5
Output:
2
Key concepts
sliding_windowsubarray_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