Skip to content

what is wrong with this code  #5

@deepgarggg

Description

@deepgarggg

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<=2*10**5 and len(array)<=10**9:
    quicksort(array, 0, len(array) - 1)
    print(array[0:N])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions