Given an array of integers nums, your task is to sort the array in ascending order and return it.
Here's the catch: you must solve this problem without using any built-in sorting functions (like sort(), sorted(), etc.). Your solution must achieve O(n log n) time complexity and use the smallest space complexity possible.
This is a fundamental computer science problem that tests your understanding of sorting algorithms. You'll need to implement one of the classic sorting algorithms like Merge Sort, Quick Sort, or Heap Sort from scratch.
Example: Given [5, 2, 3, 1], you should return [1, 2, 3, 5]
Input & Output
Visualization
Time & Space Complexity
Always makes n(n-1)/2 comparisons regardless of input
Only uses constant extra memory for variables
Constraints
- 1 โค nums.length โค 5 ร 104
- -5 ร 104 โค nums[i] โค 5 ร 104
- Must not use built-in sorting functions
- Must achieve O(n log n) time complexity