MergeSort RunTime error

def mergeSort(arr):
if len(arr) > 1:
mid = len(arr)/2
L = arr[:mid]
R = arr[mid:]

    mergeSort(L)
    mergeSort(R)

    i = j = k = 0

    while i < len(L) and j < len(R):
        if L[i] < R[j]:
            arr[k] = L[i]
            i+=1
        else:
            arr[k] = R[j]
            j+=1
        k+=1

        while i < len(L):
            arr[k] = L[i]
            i+=1
            k+=1

        while j < len(R): 
            arr[k] = R[j] 
            j+=1
            k+=1

n = int(input())
arr = [int(no) for no in input().split()]
mergeSort(arr)
print(arr)

#doubt not resolved

hi @Pratyush-Goyal-2209899605690919

we expect mid to be a number but we are getting it as float
so use
mid = len(arr)//2 to get a integer

1 Like

Thank you!
Also in line
arr = [int(no) for no in input().split()]
how do i use my variable β€˜n’ that i got from the user in the above line?
what change should i make in that line. currently my program is not written for β€˜n’ numbers.

hi @Pratyush-Goyal-2209899605690919

use arr1 = arr[n:] to get only n elements of array

1 Like

and then i sort and print arr1 right?
Is this the only way to take n elements in the array? Isn’t there a more subtle way?

HI @Pratyush-Goyal-2209899605690919
NO I DONT THINK SO