FastPrepMerge Several Sorted Arrays
Problems/Merge Several Sorted Arrays

Merge Several Sorted Arrays

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: A Software Engineer 2 entry lists two coding tasks under Round 1, and this is one of them: combine several integer arrays, each already sorted, into a single sorted array. Beyond that one line the entry says nothing about it.

Our choices: repeated values are kept, arrays may be empty, there are 1 to 1000 arrays holding at most 2000 values in total, values run from -10^5 to 10^5, and the examples are new.

The judged task matches the report at about 90%.

You are given a list of integer arrays, arrays. Each array is already sorted from smallest to largest, and some arrays may be empty.

Return one array that holds every value from every input array, sorted from smallest to largest. Keep repeated values: if a value appears three times in total, it appears three times in the answer.

Function

mergeSortedArrays(arrays: int[][]) → int[]

Examples

Example 1

arrays = [[1,4,9],[2,3,10],[5]]return = [1,2,3,4,5,9,10]

Taking the smallest front value each time gives 1, 2, 3, 4, 5, 9, 10.

Example 2

arrays = [[-3,0,0],[],[0,7]]return = [-3,0,0,0,7]

The empty array adds nothing. The three zeros all stay: [-3, 0, 0, 0, 7].

Example 3

arrays = [[6,8]]return = [6,8]

With one array there is nothing to merge, so it comes back unchanged.

Constraints

  • 1 <= arrays.length <= 1000
  • 0 <= arrays[i].length, and all arrays together hold at most 2000 values
  • -10^5 <= arrays[i][j] <= 10^5
  • Each arrays[i] is sorted in non-decreasing order.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[] mergeSortedArrays(int[][] arrays) {
    // Write your code here.
}
Checking account…