#K4826. Continuous Subarray Sum
Continuous Subarray Sum
Continuous Subarray Sum
In this problem, you are given an array of integers and a target sum. Your task is to determine if there exists a continuous subarray whose sum equals the given target. Formally, if the array is denoted by (a_0, a_1, \dots, a_{n-1}), you need to check if there exist indices (i) and (j) with (0 \le i \le j < n) such that: [ \sum_{k=i}^{j} a_k = target ] This problem requires an efficient solution, ideally in (O(n)) time using techniques such as prefix sums and hash maps. The input will be read from standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The input format is as follows:
- The first line contains a single integer (n) indicating the number of elements in the array.
- The second line contains (n) space-separated integers representing the elements of the array.
- The third line contains a single integer representing the target sum.
outputFormat
Output a single line containing either True
or False
(without quotes). Print True
if there exists a continuous subarray that sums exactly to the target, otherwise print False
.## sample
5
1 2 3 4 5
9
True