Time limit is exceeding for 1 test case. The other test case works fine. Please help. Here is my code-
Also, is there any shorter way to take input from the user?
Time limit is exceeding for 1 test case. The other test case works fine. Please help. Here is my code-
Also, is there any shorter way to take input from the user?
Hey @LPLC0059, there were some small errors in your cod. I have modified it so that it can pass all the test cases. Please see the code given below :
def findp(a,s,e):
j=s-1
pivot = a[e]
for i in range(s,e):
if a[i]<=pivot:
j+=1
a[i],a[j]=a[j],a[i]
j+=1
a[j],a[e]=a[e],a[j]
return j
def fun(a,s,e):
if s>=e:
return
pivot=findp(a,s,e)
fun(a,s,pivot-1)
fun(a,pivot+1,e)
a=[]
n=int(input())
x=input()
b=x.split()
for i in b:
a.append(int(i))
fun(a,0,n-1)
for i in a:
print(i,end=' ')
I hope this helps you resolve your doubt
Happy coding