#K86787. Subarray Sum with Target
Subarray Sum with Target
Subarray Sum with Target
Given an array of integers and a target integer, determine whether there exists a contiguous subarray whose sum is equal to the target.
This can be formulated mathematically as follows: Find indices \( l \) and \( r \) (with \( 0 \le l \le r < n \)) such that
\[
\sum_{i=l}^{r} a_i = target
\]
If such a subarray exists, output True
; otherwise, output False
.
inputFormat
The input is provided via standard input as follows:
- The first line contains an integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) space-separated integers.
- The third line contains a single integer representing the target sum.
outputFormat
Output a single line with either True
or False
depending on whether a contiguous subarray with sum equal to the target exists.
6
2 4 -1 2 1 6
5
True