This algorithm is $O(n)$ only for non-negative integers, $O(n~log~n)$ otherwise. I think there is no $O(n)$ solution for mixed positive/negative numbers, though I cannot formally prove it.
First, calculate the cumulative sum over the array. This yields an array of length $n+1$
$$\{b_1,b_2,...,b_{n+1}\} = \{0, a_1,a_1+a_2,...\}$$
and allows the calculation of any sum over a range $i..j$ in constant time as $b_{j+1}-b_i$.
If all $a_i$ are non-negative, $\{b_1,b_2,...\}$ is already monotonic. If this is not the case, sort it. Also store the array of indices.
Now you can start with two pointers, called $p_1$ and $p_2$, both initialized to $b_1$. Perform the following algorithm:
Both the cumulative sum and the search require exactly one pass over the array, so the algorithm is of time complexity $O(n)$ for non-negative numbers. In the general case, a sort is required which results in a complexity of $O(n~log~n)$.
Example
s=1
a=[1, -1, 1, -1]
Calculate the prefix sums:
b=[0, 1, 0, 1, 0]
Sort b, keep track of the original indices.
b=[0, 0, 0, 1, 1]
i=[1, 3, 5, 2, 4]
Use the two-pointer method
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 0 < 1 => rule 2
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 0 < 1 => rule 2
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 0 < 1 => rule 2
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 1 == 1 => rule 3
Look up indices
i=[1, 3, 5, 2, 4]
p1 ^
p2 ^
=> solution: sum from 1 inclusive to 2 exclusive is 1
=> length of solution is 2 - 1 = 1 (accept)
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 1 == 1 => rule 3
Look up indices
i=[1, 3, 5, 2, 4]
p1 ^
p2 ^
=> solution: sum from 3 exclusive down to 2 inclusive is 1
=> length of solution is 2 - 3 = -1 (we already have a solution of length 1 => reject)
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 1 == 1 => rule 3
Look up indices
i=[1, 3, 5, 2, 4]
p1 ^
p2 ^
=> solution: sum from 5 exclusive down to 2 inclusive is 1
=> length of solution is 2 - 5 = -3 (we already have a solution of length 1 => reject)
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 1 == 1 => rule 3
Look up indices
i=[1, 3, 5, 2, 4]
p1 ^
p2 ^
=> solution: sum from 5 exclusive down to 4 inclusive is 1
=> length of solution is 4 - 5 = -1 (we already have a solution of length 1 => reject)
b=[0, 0, 0, 1, 1]
p1 ^
p2 ^
p2 - p1 = 0 < 1 => rule 2
rule 2 not applicable: pointer reached end, terminate.
The final solution is: sum from 1 inclusive to 2 exclusive, length 1