Merge sort algorithm


my code is giving right output but on submission it is giving tle

The logic of your code is fine. The problem is TLE (Time Limit Exceeded). The code is not fast enough to complete within the time limits.
Try replacing the following section of your code:

L=[0]*n1
R=[0]*n2
for i in range(0,n1):
	L[i]=lst[l+i]
for j in range(0,n2):
	R[j]=lst[mid+1+j]

with this:

L = lst[l:mid+1]
R = lst[mid+1:h+1]

Python’s in-built list slicing is much faster than for loops and hence the TLE is resolved.

Hope this helps!

okay thank you so much

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.