#K86717. Zero Sum Subarray Detection
Zero Sum Subarray Detection
Zero Sum Subarray Detection
Given an array of integers, determine whether there exists a contiguous subarray whose sum is equal to zero. Formally, you need to check if there exist indices \(l\) and \(r\) (with \(l \le r\)) such that:
[ \sum_{i=l}^{r} a_i = 0 ]
If such a subarray exists, output Yes
; otherwise, output No
. The array may contain positive, negative integers, or even zero.
Example:
Input: 5 1 2 -3 4 5 Output: Yes
inputFormat
The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.
Note: For an empty array, the first line will be 0.
outputFormat
Output a single line with Yes
if there exists a contiguous subarray whose sum is 0, otherwise output No
.
5
1 2 -3 4 5
Yes