Pocket Gems | Phone | Subarray sum equal to k
Anonymous User
402

Given an array of integers nums and a target value k determine if the array contains a contiguous subarray such that the sum of the elements of this subarray is k

Eg,
Input: nums=[6,1,3,-2,-1,3,5], k=2
Output: True
Explanation:
1+3-2=2=k

Input: nums=[-1,2,6,-5], k=5
Output: False
Explanation:
No such contiguous subarray exists

Similar to: https://leetcode.com/problems/subarray-sum-equals-k/

Comments (2)