Subarray in middle
Input
find_subarray_with_sum([1, 2, 3, 7, 5], 12)
Output
(1, 3)
The subarray [2, 3, 7] (indices 1 to 3) sums to 12.
Full lesson preview
Locate a contiguous subarray of positive integers that sums to a target using the sliding window technique.
Problem statement
Task
Examples
Input
find_subarray_with_sum([1, 2, 3, 7, 5], 12)
Output
(1, 3)
The subarray [2, 3, 7] (indices 1 to 3) sums to 12.
Input format
Output format
Constraints
Samples
Input
[1, 4, 20, 3, 10, 5], 33
Output
(2, 4)
20 + 3 + 10 = 33, indices 2 through 4.