FastPrepMerge Two Sorted Arrays
Problems/Merge Two Sorted Arrays

Merge Two Sorted Arrays

Capgemini logoCapgemini● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

Given two integer arrays first and second, each sorted in non-decreasing order, return a new array containing every value from both inputs in non-decreasing order.

Retain every occurrence of a value, including duplicates within one input or across both inputs.

Function

mergeSortedArrays(first: int[], second: int[]) → int[]

Examples

Example 1

first = [1,2,4]second = [1,3,4]return = [1,1,2,3,4,4]

The two values equal to 1 and the two values equal to 4 are all retained in sorted order.

Example 2

first = []second = [2,2]return = [2,2]

The first array is empty, so the result contains both values from second.

Example 3

first = [-5,-1,0]second = [-3,2]return = [-5,-3,-1,0,2]

Values from the two arrays alternate in the merged ordering.

Constraints

  • 0 <= first.length <= 200000
  • 0 <= second.length <= 200000
  • Every value is a signed 32-bit integer.
  • Both input arrays are sorted in non-decreasing order.

More Capgemini problems

  • Most Recent Order for Each CustomerONSITE INTERVIEW · Seen Oct 2026
  • Contains DuplicatePHONE SCREEN · Seen Sep 2026
  • Detect a Linked-List CycleONSITE INTERVIEW · Seen Sep 2026
All Capgemini interview questionsSee Capgemini hiring insights
Saved
class Solution {
    public int[] mergeSortedArrays(int[] first, int[] second) {
      // Write your code here.
    }

}
Checking account…