Merge 2 Arrays
Updated
Problem statement
Given two sorted arrays, merge them to form a single, sorted array with all items in non-decreasing order.
Function
mergeArrays(a: int[], b: int[]) → int[]
Complete the function mergeArrays in the editor below.
mergeArrays has the following parameter(s):
int a[n]: a sorted array of integersint b[n]: a sorted array of integers
Returns
int[n]: an array of all the elements from both input arrays in non-decreasing order
Examples
Example 1
a = [1, 2, 3]b = [2, 5, 5]return = [1, 2, 2, 3, 5, 5]Merge the arrays to create array c as follows: a[0] < b[0] -> c = [a[0]] = [1] a[1] < b[0] -> c = [a[0], b[0]] = [1, 2] a[1] < b[1] -> c = [a[0], b[0], a[1]] = [1, 2, 2] a[2] < b[1] -> c = [a[0], b[0], a[1], a[2]] = [1, 2, 2, 3] No more elements in a -> c = [a[0], b[0], a[1], a[2], b[1], b[2]] = [1, 2, 2, 3, 5, 5] Elements were alternately taken from the arrays in the order given, maintaining precedence.
Constraints
1 < n <= 10^50 <= a[i], b[i] <= 10^9where0 <= i < n
More Oracle interview questions
- Course ScheduleONSITE INTERVIEW · Seen Nov 2026
- Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
- Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
- Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
- Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
- Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
- Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
- Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OA
- Meandering ArrayVerisk · OA
- Count Cross-Array Target-Sum PairsVisa · OA
- Can Every Package Fit in a BoxIMC Trading · OA
- Minimum Tunnel Crossing TimeArcesium · OA
- Merge 2 ArraysIBM · OA
- Get Maximum PairsAmazon · OA
- Find Maximum GreatnessTwilio · OA
- Merge Sorted ArrayAtlassian · OA
- Binge WatchingVanguard · OA