Quick Sort
Updated
Problem statement
Given an integer array nums, sort it in increasing order using quicksort and return the sorted array. Keep repeated values.
Write the sort yourself instead of calling a built-in sort. The judge checks only the returned array, so this rule is not checked automatically.
Function
sortArray(nums: int[]) → int[]Examples
Example 1
nums = [5,2,9,1,5,6]return = [1,2,5,5,6,9]In increasing order the values are 1, 2, 5, 5, 6, 9. Both 5s are kept.
Example 2
nums = [3,-1,0]return = [-1,0,3]Negative values come first: [-1, 0, 3].
Example 3
nums = [7]return = [7]A single element is already sorted.
Constraints
1 <= nums.length <= 5000-10^5 <= nums[i] <= 10^5
More Microsoft Onsite Interview questions
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Merge Intervals from Start and End ListsWalmart · ONSITE INTERVIEWWalmart interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Maximum Intervals Overlapping a Fixed-Length WindowBooking.com · ONSITE INTERVIEW