Merge Two Sorted Arrays
Updated
Problem statement
You are given two integer arrays, first and second, each sorted from smallest to largest. Return a new array containing all values from both inputs, also sorted from smallest to largest.
Keep every occurrence, including repeated values within either input and values present in both arrays. Either input may be empty.
Function
mergeSortedArrays(first: int[], second: int[]) → int[]Examples
Example 1
first = [1,4,4]second = [2,4,7]return = [1,2,4,4,4,7]Every occurrence of 4 remains.
Example 2
first = []second = [0,3]return = [0,3]An empty input contributes no values.
Example 3
first = [-5,-1,6]second = [-3,6]return = [-5,-3,-1,6,6]Negative values and both copies of 6 are retained.
Constraints
0 <= first.length, second.length <= 10^5.- The combined length is at most
2 * 10^5. - Values are signed 32-bit integers.
- Both inputs are sorted in nondecreasing order.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Assign CookiesAmazon · PHONE SCREEN
- Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
- Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Parse and Sort Integer DataLegora · PHONE SCREEN