Sort an Array
Updated
Problem statement
Given an integer array nums, sort it in non-decreasing order and return the sorted array.
Write the sort yourself, for example merge sort or quick sort, instead of calling a built-in sort function.
Function
sortArray(nums: int[]) → int[]Examples
Example 1
nums = [14,-6,0,9,-6,3]return = [-6,-6,0,3,9,14]The smallest value is -6, which appears twice, so both copies come first. The other values follow from smallest to largest: 0, 3, 9, 14.
Example 2
nums = [100,-100]return = [-100,100]The two values are out of order, so they trade places.
Example 3
nums = [2,4,4,10]return = [2,4,4,10]The array is already in non-decreasing order, so it comes back unchanged.
Constraints
1 <= nums.length <= 2000-10^5 <= nums[i] <= 10^5
More Bank of America Onsite Interview questions
- Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
- Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
- N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
- Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
- Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
- Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
- Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
- Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
- Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
Similar questions at other companies
- 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
- Generalized N-SumBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Count InversionsExpedia · OAExpedia interview questions
- Count InversionsNutanix · OANutanix interview questions
- Closest Pair of PointsCitadel · PHONE SCREENCitadel interview questions
- Temporal AnomaliesInMobi · OAInMobi interview questions
- Minimum Euclidean Distance Between PointsLuma AI · OALuma AI interview questions
- Count Inversions With Merge SortAdobe · PHONE SCREENAdobe interview questions