We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defquickSort(arr)# Write your code herereturnarrifarr.length<=1pivot=arr.delete_at(arr.length/2)#Selectthepivotelementleft,right=arr.partition{|x|x<pivot}#Partitionthearray# Recursively sort and combinereturnquickSort(left)+[pivot]+quickSort(right)end
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 1 - Partition
You are viewing a single comment's thread. Return to all comments →
The quicksort algorithm in Ruby