The problem. Given an array of integers nums and an integer k, return the number of subarrays whose elements add up to exactly k. The numbers may be negative.
nums = [1, 1, 1], k = 2 -> 2 ([1, 1] twice)
nums = [1, 2, 3], k = 3 -> 2 ([1, 2] and [3])
nums = [3, 4, 7, 2, -3, 1, 4, 2], k = 7 -> 4Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson