Write a method select which takes an Array<Int> and an Int value n,
and returns the nth smallest value in the array. The array will have
at least 1 element, and n will be positive and less
than the length of the array.
You may NOT solve this problem by sorting the array - instead, you should use the
partition method described
here.
You should import it using the following code:
The best algorithm for this is called QuickSelect, and it is described here.
You do not need a private helper function to solve this problem, but you are allowed to use one if you wish. Note that you may NOT modify the input array, so you may need to copy it.
Stuck? You may find these lessons helpful: