#K71992. Subarray Sum
Subarray Sum
Subarray Sum
Given an array of integers, determine if there exists a contiguous subarray (of any non-zero length) whose sum is equal to a given target value.
The input consists of the number of elements in the array and the target sum. Your task is to check all possible contiguous subarrays using a sliding window technique. If any subarray sums exactly to the target, print True
; otherwise, print False
.
Note: If the array is empty, the answer is False
.
inputFormat
The first line contains two integers n and target separated by a space, where n is the number of elements in the array and target is the desired sum.
The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single line to standard output containing either True
if there exists a contiguous subarray whose sum equals target, or False
if no such subarray exists.
5 9
1 2 3 4 5
True