Facebook | Subarray Sum Equals K
16815
Jun 06, 2016
Aug 08, 2019

Given a sequence of positive integers nums and an integer k, return whether there is a continuous sequence of nums that sums up to exactly k.

Example 1:

Input: nums = [23, 5, 4, 7, 2, 11], k = 20
Output: true
Output: 7 + 2 + 11 = 20

Example 2:

Input: nums = [1, 3, 5, 23, 2], k = 8
Output: true
Explanation: 3 + 5 = 8

Example 3:

Input: nums = [1, 3, 5, 23, 2], k = 7
Output: false
Explanation: because no sequence in this array adds up to 7.
Comments (38)