← Back to all problems
Medium

Subarray Sum Equals K

Updated Feb 24, 2026

Problem

Count contiguous subarrays that sum to k.

Constraints

1 <= nums.length <= 2*10^4

Examples

Example 1

Input: {"nums": [1, 1, 1], "k": 2}
Output: 2

Function Signature

def subarraySum(self, nums: list[int], k: int) -> int

How to Submit

Implement a Solution class with a subarraySum method.

Your method will be called with the input parameters and should return the answer.