Subarray Sum Equals K Problem
Subarray Sum Equals K Problem — ExecCode Medium DSA Practice
Solve the Subarray Sum Equals K problem on ExecCode. Free online medium DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k. A subarray is a contiguous non-empty sequence of elements within an array.
Examples
Input nums = [1, 2, 1, 2, 1], k = 3; Output 4. Input nums = [3, 4, 7, 2, -3, 1, 4, 2], k = 7; Output 4. Input nums = [1, 1, 1], k = 2; Output 2
Constraints
1 ≤ nums.length ≤ 2×10⁴ -1000 ≤ nums[i] ≤ 1000 -10⁷ ≤ k ≤ 10⁷
Practice Subarray Sum Equals K free on ExecCode. Browse DSA problems, topic map, and placement guides.