Merge Sort in Kotlin I started learning kotlin recently,with some background in java.

So I wrote a merge sort algorithm in kotlin.
I am looking for best practices in kotlin and looking for this code review.

I also wanted to know about its efficiency and ways to increase it.

Thanks

fun merge(list: List&lt;Int&gt;,lo: Int,hi: Int): List&lt;Int&gt;{
    val mid=(lo+hi)/2
    var i=lo
    var j=mid+1
    var new_list=mutableListOf&lt;Int&gt;()
    for(k in 0..(lo-1)) new_list.add(list[k])
    while(!(i==mid+1 &amp;&amp; j==hi+1)){
        if(i==mid+1){
            new_list.add(list[j])
            j++
        }
        else if(j==hi+1){
            new_list.add(list[i])
            i++
        }
        else if(list[i]&gt;list[j]){
            new_list.add(list[j])
            j++
        }
        else{
            new_list.add(list[i])
            i++
        }
    }
    for(k in (hi+1)..(list.size-1)) new_list.add(list[k])
    return new_list.toList()
}

fun mergeSort(list: List&lt;Int&gt;,lo: Int,hi: Int): List&lt;Int&gt;{
    if(lo&lt;hi){
        val mid=(lo+hi)/2
        val list1=mergeSort(list,lo,mid)
        val list2=mergeSort(list1,mid+1,hi)
        val list3=merge(list2,lo,hi)
        return list3
    }
    return list
}
I have zero experience with Kotlin, but I can tell you how to make your implementation run faster. You could allocate the auxiliary space only once throughout the entire algorithm, and you essentially merge from one array to other, then at a higher recursion level, you swap their roles and merge in opposite direction. You can learn about this approach here.

Also, one nitpick: in most languages (I know), the sorting method/function does not return any list; they just modify the input array.

Hope that helps.