Sort an Array Fast
Updated
Problem statement
Given an array of integers nums, return a new array with the same numbers in increasing order. Equal numbers all stay in the result.
Write the sort yourself with a method that takes O(n log n) time on average, such as quicksort or merge sort. The judge checks only the returned array, so this rule is for your practice and is not checked.
Function
sortNumbers(nums: int[]) → int[]Examples
Example 1
nums = [5,-2,9,0,-2]return = [-2,-2,0,5,9]In increasing order: -2, -2, 0, 5, 9. Both copies of -2 stay in the result.
Example 2
nums = [42]return = [42]One number is already sorted.
Example 3
nums = [10,9,100,1]return = [1,9,10,100]Numbers are compared by value: 1 < 9 < 10 < 100. Comparing them as text would wrongly put 10 and 100 before 9.
Constraints
1 <= nums.length <= 2000-10^5 <= nums[i] <= 10^5
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- 3SumAmazon · PHONE SCREEN
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions