Back to course home
0% completed
Vote For New Content
Simpler with nested for-loops?
tahriris
Dec 10, 2024
Given that the optimal runtime is quadratic, why not just use nested for-loops?
def find_subarrays(arr, target): subarrays = [] for i in range(len(arr)): product = 1 for j in range(i, len(arr)): product *= arr[j] if product >= target: break subarrays.append(arr[i : j + 1]) return subarrays
2
0
Comments
Comments