educative.io

Giving wrong output for smallest subarray with given sum

Error in smallest_subarray_with_given_sum solution in grokking the coding interview course.
For smallest_subarry_with_given_sum.
The given solution doesnt give desired output for the following scneario.
smallest_subarray_with_given_sum(9, [2, 1, 5, 2, 8])))
Desired_output = 0
Ouput_obtained = 2

Probably you missed the “greater than” part of the problem. The smallest subarray with sum “greater than or equal” to 9 is [2, 8].

See problem definition:

find the length of the smallest contiguous subarray whose sum is greater than or equal to ‘S’