Why this code is not able to submit

def partition(arr, low, high):
i = (low - 1)
pivot = arr[high]
for j in range(low, high):

    if arr[j] <= pivot:

        i = i + 1
        arr[i], arr[j] = arr[j], arr[i]

arr[i + 1], arr[high] = arr[high], arr[i + 1]
return (i + 1)

def quickSort(arr, low, high):
if low < high:

    pi = partition(arr, low, high)
    quickSort(arr, low, pi - 1)
    quickSort(arr, pi + 1, high)

n=int(input())
arr = []
for d in range(n):
arr.append(int(input()))
n = len(arr)
quickSort(arr, 0, n - 1)
for i in range(n):
print("%d" % arr[i]),

Hey @Deep50, the worst case complexity of you code is O(n^2). Read about randomized quick sort and implement that.

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

other than this my program is going to work ?

Hey @Deep50, it seems fine.

import random def quicksort(arr, start, stop): if (start < stop): pivotindex = partitionrand(arr, start, stop) quicksort(arr, start, pivotindex - 1) quicksort(arr, pivotindex + 1, stop) def partitionrand(arr, start, stop): randpivot = random.randrange(start, stop) arr[start], arr[randpivot] = arr[randpivot], arr[start] return partition(arr, start, stop) def partition(arr, start, stop): pivot = start i = start + 1 for j in range(start + 1, stop + 1): if arr[j] <= arr[pivot]: arr[i], arr[j] = arr[j], arr[i] i = i + 1 arr[pivot], arr[i - 1] = arr[i - 1], arr[pivot] pivot = i - 1 return (pivot) if name == “main”: N=int(input()) array = [int(number) for number in input().split()] if N==len(array) and N<=2*105 and len(array)<=109: quicksort(array, 0, len(array) - 1) print(array)

now what is problem on this code

Hey @Deep50, save your code on cb.lk/ide and than share the link