Hi !
I was trying a quick sort program:
import random
length = int(input())
string_input = input()
num_list = [int(num) for num in string_input.split(" ") ]
print(num_list)
def partitionRandom(arr, low, high):
if low == high:
return
randomPivot = random.randrange(low, high)
arr[low], arr[randomPivot] = arr[randomPivot], arr[low]
return partition(arr, low, high)
def partition(arr, low, high):
if low == high:
return
pivot = low
i = (low + 1)
for j in range(low+1, high+1):
if arr[j] <= arr[pivot]:
arr[i], arr[j] = arr[j], arr[i]
i += 1
arr[pivot], arr[i-1] = arr[i-1], arr[pivot]
return (i-1)
def quick_sort(arr, low, high):
if low < high:
pivotIndex = partitionRandom(arr, low, high)
quick_sort(arr, low, pivotIndex-1)
quick_sort(arr, pivotIndex+1, high)
quick_sort(num_list, 0, length-1)
for num in num_list:
print(num, end=" ")
But this one fails in the negative test case, which is unknown, when submitting, it shows to check for negative numbers, my code works locally, I am unable to check where it fails.
Please have a look once…


