Challenge 3: Sort an Array

Given an array of numbers, sort it in ascending order.

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.


  1. An array testVariable containing numbers.
  2. The length of the array


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 70+ hands-on prep courses.