BackeasyArrays

Subarray Sum Matches 2 Solution

Problem Statement

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

Example 1
Input
{"arr":[1,2,3,4,5],"target":5}
Output
2

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

Example 2
Input
{"arr":[10,20,30,40,50],"target":60}
Output
1

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

Constraints

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