Why time limit coming after randomizing the list using shuffle in quicksort?

from random import shuffle
def partition(unsort,s,e):
i = s-1
pivot = unsort[e]
for j in range(s,e):
if unsort[j] <= pivot:
i+=1
unsort[i],unsort[j] = unsort[j],unsort[i]

unsort[i+1],unsort[e] = unsort[e],unsort[i+1]
return i+1

def quicksort(unsort,s,e):
if s>=e:
return
p = partition(unsort,s,e)
quicksort(unsort,s,p-1)
quicksort(unsort,p+1,e)

t = int(input())
unsort = [int(x) for x in input().split()]
shuffle(unsort)
quicksort(unsort,0,t-1)
for item in unsort:
print(item,end=’ ')

Hello @arush,

Kindly share your code through ide.
Thanks :slight_smile:

Hello @arush,

The reason why you are having time limit might be because of the programming language. Try submitting the challenge in C++. As these questions are focused more for Ds Algo students, and as python is slower, even if you put the best algorithm their, it can show time limit exceeded.
Hence try with C++ or Java.
Thanks :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.