#C10377. Zero Sum Subarray of Fixed Length
Zero Sum Subarray of Fixed Length
Zero Sum Subarray of Fixed Length
Given an array of integers and an integer n, determine whether there exists a contiguous subarray of length n whose sum equals 0.
In other words, given an array \( arr \) of length \( m \) and an integer \( n \), check if there exists an index \( i \) (with \( 0 \le i \le m - n \)) such that \[ \sum_{j=i}^{i+n-1} arr[j] = 0 \]
If such a subarray exists, print True
; otherwise, print False
.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two space-separated integers \( m \) and \( n \), where \( m \) is the length of the array and \( n \) is the required subarray length.
- The second line contains \( m \) space-separated integers representing the array elements.
outputFormat
Output to standard output (stdout) a single line containing either True
or False
depending on whether a contiguous subarray of length n with sum equal to \( 0 \) exists.
7 3
1 2 -3 4 -2 2 1
True