Given an integer array, find if the target sum exists as the sum of contiguous elements.
Interview Answers
Anonymous
Oct 13, 2018
Looks like a segment tree question
Anonymous
Oct 14, 2018
Answer
Define A[i] := sum(A[0:i+1)]
create a set B
Iterate for each val in A
Return True if (target - val) in B
otherwise, add val to B
return False if none found
Anonymous
Oct 14, 2018
Typo, it should be (val - target) in B.
Runtime and space are both linear
Anonymous
Nov 7, 2018
This is just a straightforward sliding window problem. The keyword here is "contiguous".