List index out of range

def merge(a,s,e,mid):
n1 = mid-s+1
n2 = e-mid

L = [0]*(n1)
R = [0]*(n2)

for i in range(0,n1):
    L[i] = a[s+i]
for j in range(0,n2):
    R[j] = a[mid+1+j]
    
i = 0
j= 0
k = s
while(i< n1 and j< n2):
    if L[i]<=R[j]:
        a[k] = L[i]
        k +=1
        i +=1
    else:
        a[k] = R[j]
        print(temp)
        k+=1
        j+=1
while i<=n1:
    a[k] = L[i]
    k+=1
    i+=1
while j<=n2:
    a[k]=R[j]
    k+=1
    i+=1

def mergeSort(a,s,e):
if s==e:
return
mid = s+(e-1)//2
mergeSort(a,s,mid)
mergeSort(a,mid+1,e)
merge(a,s,e,mid)

l = [8,9,16,1,2,3,4,5]
mergeSort(l,0,len(l)-1)
print(l)

No one here to clear my doubt.

Hello @arush,

Sorry for the delay, kindly share your code through the online ide .
Also, debugging code is a task that each and every programmer should be thorough with, and it can only be achieved by doing it yourself.
You should only take help when its getting really tough for you to know where is the problem.
Some tips you can use,

  • Use print function as much as you want.Think a problem is lurking around your function definition? Use a print.
  • Look for worst case scenarios, places where your logic would utterly fail.

Also, all the challenges provided within the course are properly tested, hence, if your code is not working, your code is wrong, there is very little chance that the online judge or compiler is making a mistake.

If nothing works, clear everything out in the editor, and start over.

Happy Learning,
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.