Implement Quicksort
Updated
Problem statement
Sort nums in increasing numeric order using your own quicksort implementation, and return the sorted array. Preserve every occurrence of a repeated value.
Partition the array and process the remaining partitions. Do not call a library sorting function. You may mutate the input array, and may use an explicit stack to avoid recursive call-depth limits.
The returned values are checked by the runner; the quicksort and no-library-sort requirements are part of the exercise and solution review.
Function
quickSort(nums: int[]) → int[]Examples
Example 1
nums = [3,1,2,1]return = [1,1,2,3]Increasing order is 1,1,2,3, with both occurrences of 1 retained.
Example 2
nums = []return = []An empty array is already sorted.
Constraints
0 <= nums.length <= 3000-10^6 <= nums[i] <= 10^6
More JP Morgan Chase Onsite Interview questions
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU CacheONSITE INTERVIEW · Seen Nov 2026
- Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
- Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
- K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
- Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
- Two SumONSITE INTERVIEW · Seen Nov 2025
- Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
- Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
- Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024
Similar questions at other companies
- Predict AnswerAmazon · OA
- Most Segments That Sort the ArrayRippling · OARippling interview questions
- Alternating Jumps to the Last IndexExpedia · OAExpedia interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
- 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