Subarray Sum Equals K

Problem

Given an integer array nums and integer k, return the total number of contiguous subarrays whose sum equals k.

Input / Output

  • Input: integer array nums, integer k.
  • Output: count of contiguous subarrays summing to exactly k.

Constraints

  • 1 ≤ nums.length ≤ 2 × 10^4
  • -1000 ≤ nums[i] ≤ 1000 (values may be negative)

Example

nums = [1,1,1], k = 2
Output: 2
added …
LeaderboardSalaryAccount