Back to course home
0% completed
Vote For New Content
Easy Alternate Solution: From left to Right [Python]
k
Jul 7, 2023
from collections import deque class Solution: def findSubarrays(self, arr, target): result = [] product = 1 right = 0 for left in range(len(arr)): while right < len(arr): temp_product =product * arr[right] if temp_product < target: product = temp_product right += 1 else: break # Product will always be less than target. # Let's append all combination from left to right. # i.e. for subarray [2,3,4] # left=0th index, # right = 3nd index which is not included in product, # target = 30 # combinations = [2], [2,3], [2,3,4] # It will not include [3], [3,4] since it will be added in next iterations temp_list = [] for i in range(left, right): # Remove the space from following two lines. I can't submit it properly. # So I have added a space before the word "append" temp_list. append(arr[i]) result. append(list(temp_list)) product /= arr[left] return result
1
0
Comments
Comments
K
k 2 years ago
Only order is be different. Solution is correct. Why is it not accepted?
Am I missing something?
Update1: It's accepting now. Thanks.
Design Gurus2 years ago
We see following error while running the solution. Can you please fix it:
NameError: name 'temp_' is not defined