BackeasyArrays

Subsequence Sum Occurrences Solution

Problem Statement

Given a one-dimensional array of integers and a target sum, determine the total count of contiguous subarrays where the sum of elements equals the target sum.

Example 1
Input
arr = [1, 2, 3, 4, 5], target_sum = 5
Output
2

Explanation: The subarrays [2, 3] and [5] have a sum equal to the target sum 5.

Example 2
Input
arr = [10, 20, 30, 40], target_sum = 60
Output
1

Explanation: The subarray [10, 20, 30] has a sum equal to the target sum 60.

Constraints

  • 1 <= arr.length <= 1000
  • -10^4 <= arr[i] <= 10^4
  • -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