Challenge 3: Sort an Array
Given an array of numbers, sort it in ascending order.
We'll cover the following
Problem Statement
Implement a function that sorts the input array testVariable
in-place.
In-place means that no extra array or any other data structure is used in the algorithm. Such algorithms produce an output in the same memory/space that contains the data by transforming the input in-place
. However, a constant extra space can be used in the form of simple variables.
Remember to solve this problem recursively.
Input
- An array
testVariable
containing numbers. - The length of the array
Output
No output. Our task is to sort the input array.
Sample Input
testVariable = [5, 4, 2, 3, 1]
length = 5
Sample Output
# No explicit output.
# However the state of array testVariable is [1, 2, 3, 4, 5]
Try it Yourself
Try this challenge yourself before examining the solution. Good luck!
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.