
Given an array of numbers nums, return a new array containing the same elements sorted in non-decreasing order. Implement the sorting logic yourself and be prepared to justify why the chosen algorithm is appropriate for general unsorted input.
Example 1:
Input: nums = [5, 2, 3, 1]
Output: [1, 2, 3, 5]
Explanation: Sorting the array in ascending order gives [1, 2, 3, 5].
Example 2:
Input: nums = [4, 1, 4, -2, 0]
Output: [-2, 0, 1, 4, 4]
Explanation: The result preserves all values, including duplicates, in sorted order.
0 <= len(nums) <= 10^5-10^9 <= nums[i] <= 10^9nums = [5, 2, 3, 1]Output[1, 2, 3, 5]WhySorting the four values in ascending order gives [1, 2, 3, 5].nums = [4, 1, 4, -2, 0]Output[-2, 0, 1, 4, 4]WhyNegative numbers and duplicates are both handled correctly.0 <= len(nums) <= 10^5-10^9 <= nums[i] <= 10^9The solution should work correctly for duplicates, negative values, and already sorted arraysdef sort_array(nums):