Implement Quicksort
Updated
Problem statement
nums is an array of integers. Write quicksort yourself and use it to put the numbers in increasing order, then return the sorted array. A value that appears several times in nums must appear the same number of times in the result.
The interview asked for quicksort, so do not call a built-in sort. The tests compare only the array you return with the correct order; they cannot tell which method produced it.
Function
sortArray(nums: int[]) → int[]Examples
Example 1
nums = [5,-3,8,0,-3,2]return = [-3,-3,0,2,5,8]In increasing order the numbers are -3, -3, 0, 2, 5, 8; both copies of -3 stay. One quicksort step with pivot 2 splits the rest into the smaller numbers [-3, 0, -3] and the larger numbers [5, 8]. The pivot is then in its final place, and each side is sorted the same way.
Example 2
nums = [4,1,4,4,2,4]return = [1,2,4,4,4,4]All four copies of 4 stay in the result, after 1 and 2.
Example 3
nums = [9,7,4,1]return = [1,4,7,9]The input is in decreasing order, so the sorted array is the same numbers reversed.
Constraints
1 <= nums.length <= 3000-5 * 10^4 <= nums[i] <= 5 * 10^4
More ByteDance Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Largest Rectangle in HistogramPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Reverse Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
- Matrix EscapePHONE SCREEN · Seen Nov 2026
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Closest Pair of PointsCitadel · PHONE SCREENCitadel interview questions
- Count Inversions With Merge SortAdobe · PHONE SCREENAdobe interview questions
- Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions
- K Largest Elements with QuickselectAMD · ONSITE INTERVIEWAMD interview questions
- Implement Merge SortSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Count InversionsExpedia · OAExpedia interview questions
- Sort an ArrayBank of America · ONSITE INTERVIEWBank of America interview questions
- Count InversionsNutanix · OANutanix interview questions
- Temporal AnomaliesInMobi · OAInMobi interview questions
- Minimum Euclidean Distance Between PointsLuma AI · OALuma AI interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience