#C14411. Zero Sum Subarray
Zero Sum Subarray
Zero Sum Subarray
Given an array of integers and an integer k
, determine whether there exists a contiguous subarray of length at least k
whose sum equals zero.
A subarray is defined as a contiguous portion of the array.
Constraints:
- $$1 \le n \le 1000$$, where
n
is the number of elements in the array. - $$-10^4 \le nums[i] \le 10^4$$ for each element
nums[i]
. - $$1 \le k \le n$$
Example:
Input: 7 1 2 -3 4 -2 -2 5 3</p>Output: True
inputFormat
The input is read from stdin and consists of three lines:
- The first line contains a single integer
n
, the number of elements in the array. - The second line contains
n
space-separated integers representing the array elements. - The third line contains a single integer
k
.
outputFormat
Print to stdout a single line containing either True
if there exists a contiguous subarray of length at least k
that sums to zero, or False
otherwise.
7
1 2 -3 4 -2 -2 5
3
True