936. Recursive Bubble Sort
Given an array of integers nums, sort the array in non-decreasing order using the recursive Bubble Sort algorithm, and return the sorted array.
- You must implement Bubble Sort using recursion only.
- Do not use built-in sorting functions (sort, sorted, Arrays.sort, etc.).
- A sorted array in non-decreasing order is an array where each element is greater than or equal to the previous one.
Example 1:
Input: nums = [7, 4, 1, 5, 3]
Output: [1, 3, 4, 5, 7]
Explanation: 1 <= 3 <= 4 <= 5 <= 7.
Thus the array is sorted in non-decreasing order.
Example 2:
Input: nums = [5, 4, 4, 1, 1]
Output: [1, 1, 4, 4, 5]
Explanation: 1 <= 1 <= 4 <= 4 <= 5.
Thus the array is sorted in non-decreasing order.
Now Your Turn!
Pick the correct output for the given inputInput: nums = [3, 2, 3, 4, 5]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 1000
- -104 <= nums[i] <= 104
- nums[i] may contain duplicate values.