BackeasyArrays

Subarray Sum Frequency 2 Solution

Problem Statement

Given an array of integers, find the number of contiguous subarrays where the sum of the elements equals a given target value.

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

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

Example 2
Input
[10, 20, 30, 40], 60
Output
0

Explanation: There is no contiguous subarray that sums up to the target value 60.

Example 3
Input
[5, 5, 5], 15
Output
1

Explanation: The subarray [5, 5, 5] sums up to the target value 15.

Constraints

  • 1 <= array length <= 1000
  • -100 <= array elements <= 100
  • -10000 <= target sum <= 10000
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