I’ve been consistently working on LeetCode problems, but when I encounter questions involving subarrays, I often run into a ‘time limit exceeded’ error. Can anyone help me find a fast Python code solution for identifying all subarrays within a list?
I tried a unique method which works but isn’t fast my code looks like this
def Find_subarrays(x):
p=[]
for i in range(len(x)):
l=[]
for j in range(i,len(x)):
l.append(x[j])
p.append(l)
return(p)
what makes this so slow
New contributor
Conner H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.