Back to course home
0% completed
Vote For New Content
Easy to follow solution
Mohammed Dh Abbas
Jul 8, 2024
import math class Solution: def findMinSubArray(self, s, arr): sum = 0 j = 0 min_sum = float('inf') for i in range(len(arr)): sum += arr[i] while sum >= s: diff = i - j + 1 min_sum = min(min_sum, diff) sum -= arr[j] j += 1 # inf happens if we have nothing >= s we want to return 0 not inf return min_sum if min_sum != float('inf') else 0
0
2
Comments
Comments
S
shanehowe100 a year ago
so the exact same solution as given?
Design Gurus7 months ago
This is exactly the same as the given solution... but with variable names that are not reflecting their meaning. Also 'sum' is a reserved word in Python.