BlackFridaySale

Join the waitlist for an extra exclusive deal

Extra savings end in
01Days
10Hrs
20Mins
11Secs
Limited spots only

1024. Quick Sorting

Given an array of integers called nums, sort the array in non-decreasing order using the quick sort algorithm and return the sorted array.

A sorted array in non-decreasing order is an array where each element is greater than or equal to all preceding elements in the array.

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 input

Input: 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 <= 105
  • -104 <= nums[i] <= 104
  • nums[i] may contain duplicate values.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<int> quickSort(vector<int>& nums) {
 
}
};
 
Test Case

Input:

Nums