Merge Sorted Array
Updated
Problem statement
nums1 has length m+n. Its first m values and all n values of nums2 are sorted nondecreasingly; the remaining positions of nums1 are capacity.
Merge both sorted sequences into nums1 and return it.
Function
mergeSortedArray(nums1: int[], m: int, nums2: int[], n: int) → int[]Examples
Example 1
nums1 = [1,2,3,0,0,0]m = 3nums2 = [2,5,6]n = 3return = [1,2,2,3,5,6]The two sorted prefixes merge in nondecreasing order.
Example 2
nums1 = [0]m = 0nums2 = [1]n = 1return = [1]The first sequence is empty.
Constraints
0 <= m, nand1 <= m+n <= 10^5.nums1.length == m+nandnums2.length == n.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
- Remove Duplicates from Sorted ArrayNykaa · PHONE SCREENNykaa interview questions
- Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
- Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Closest Vehicle and Charger in a LineSpotify · PHONE SCREEN
- Assign CookiesAmazon · PHONE SCREEN
- Correct an In-Place Array ReversalDuolingo · PHONE SCREENDuolingo interview questions
- Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
- Remove Duplicates From Sorted Array In PlaceGet My Parking · PHONE SCREEN