BackeasyArrays

Subsequence Sum Matches Target Solution

Problem Statement

Given a sequence of integers and a target sum, determine the count of contiguous subsequences within the sequence where the sum of elements equals the target sum.

Example 1
Input
[1, 2, 3, 4, 5], 5
Output
2

Explanation: The subsequences [2, 3] and [5] sum up to the target value of 5.

Example 2
Input
[1, 1, 1, 1, 1], 3
Output
3

Explanation: The subsequences [1, 1, 1], [1, 1, 1], and [1, 1, 1] sum up to the target value of 3.

Constraints

  • 1 <= sequence length <= 10^5
  • -10^5 <= element value <= 10^5
  • -10^5 <= target sum <= 10^5
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free