The Precondition Nobody Reads
The Competitive Programmer's Handbook presents this two-pointer scan for finding a contiguous subarray with sum exactly x, and states its input as an array of n positive integers.
def has_subarray_sum(a, x):
left = total = 0
for right in range(len(a)):
total += a[right]
while total > x:
total -= a[left]
left += 1
if total == x:
return True
return False
A teammate deletes the word positive from the docstring. Which input below makes the function return False even though a qualifying subarray exists?
Sign in to answer questions and track your progress
Sign In