#K86417. Subarray Sum Problem

    ID: 36860 Type: Default 1000ms 256MiB

Subarray Sum Problem

Subarray Sum Problem

Given an array of n integers and a target integer \(T\), determine if there exists a contiguous subarray whose sum is exactly equal to \(T\). Formally, you need to check if there exist indices \(i\) and \(j\) such that \(0 \le i \le j < n\) and \(\sum_{k=i}^{j} h[k] = T\). An efficient approach is to use prefix sums and a hash set to check for \(prefixSum - T\) at each step.

inputFormat

The first line contains two integers (n) and (T) separated by a space. The second line contains (n) integers, representing the elements of the array.

outputFormat

Output a single line with either "True" if there exists a contiguous subarray whose sum equals (T), or "False" otherwise.## sample

5 12
1 2 3 7 5
True