#K71002. Subarray Sum Problem
Subarray Sum Problem
Subarray Sum Problem
Given an array of integers and a target sum value, determine whether there exists a contiguous subarray that sums exactly to the target.
You are given an integer n representing the number of elements in the array, followed by n space-separated integers representing the array elements. The next input is an integer representing the target sum.
Your task is to check if there exists a subarray whose sum equals the target. If such a subarray exists, print True; otherwise, print False.
Note: The subarray should consist of consecutive elements of the given array and can include negative numbers as well.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains an integer n indicating the number of elements in the array.
- The second line contains n space-separated integers representing the array.
- The third line contains an integer target representing the target sum.
outputFormat
Print True if there exists a contiguous subarray whose sum is equal to the target; otherwise, print False. The output is written to standard output (stdout).
## sample5
1 2 3 7 5
12
True