FastPrepMerge Sorted Arrays with Duplicates
Problems/Merge Sorted Arrays with Duplicates

Merge Sorted Arrays with Duplicates

Mygate logoMygate● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Mygate phone screen for a full-time role. The report mentions merging arrays that have duplicates, but leaves out the order and the duplicate rules. Here we assume the inputs are sorted and keep all repeats.

Our version is about 80% the same as the reported question.

Given two integer arrays a and b, each sorted from smallest to largest, return a new array containing all their elements, from smallest to largest.

Keep one result for every input entry, including duplicates within an input or across both inputs. Do not change either input. Either array, or both, may be empty.

Function

mergeSortedArrays(a: int[], b: int[]) → int[]

Examples

Example 1

a = [1,2,2]b = [2,3]return = [1,2,2,2,3]

The value 2 occurs twice in a and once in b, so it occurs three times in the result.

Example 2

a = []b = [-2,0,0]return = [-2,0,0]

An empty first array contributes no elements.

Constraints

  • 0 ≤ a.length, b.length ≤ 10,000.
  • −100,000,000 ≤ every array value ≤ 100,000,000.
  • Both input arrays are sorted in nondecreasing order.

More Mygate Phone Screen questions

  • Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
  • Maximum Subarray SumPHONE SCREEN · Seen Sep 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Sep 2026
  • Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
  • Elements Occurring More Than n/3 TimesPHONE SCREEN · Seen Jan 2025
  • Frog Jump: Minimum EnergyPHONE SCREEN · Seen Jan 2025
  • Left View of a Binary TreePHONE SCREEN · Seen Jan 2025
  • Two SumPHONE SCREEN · Seen Aug 2024
  • Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024
  • Minimum Subarray SumPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Assign CookiesAmazon · PHONE SCREEN
  • Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
  • Squares of a Sorted ArrayStryker · PHONE SCREEN
  • Squares of a Sorted ArrayGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Merge Into the Zero-Padded ArrayAdobe · PHONE SCREENAdobe interview questions
  • Three Partition ArrayMicrosoft · PHONE SCREENMicrosoft interview questions
  • Sorted Squares in Descending OrderWhatNot · PHONE SCREENWhatNot interview questions
  • Assign CookiesExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
  • Merge Two Sorted ArraysZillow · PHONE SCREENZillow interview questions
All Mygate interview questionsSee Mygate hiring insights
Saved
class Solution {
    public int[] mergeSortedArrays(int[] a, int[] b) {
        // write your code here
    }
}
Checking account…