FastPrepMerge Sorted Arrays in Place
Problems/Merge Sorted Arrays in Place

Merge Sorted Arrays in Place

Expedia logoExpedia● EasyNEW GRADINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report requires an in-place merge. The first array is changed and returned, and that is what gets checked. We chose how the spare room is shown and the limits. Our version is about 97% the same as the reported question.

The first m entries of nums1 and all n entries of nums2 are sorted. The first array has m+n slots, with its remaining entries serving only as unused capacity.

Merge both valid sequences into nums1 in nondecreasing order, in place. Ignore the original capacity values. Return the mutated first array as the observable result. The final approach should use constant auxiliary space.

Function

mergeSortedArray(nums1: int[], m: int, nums2: int[], n: int) → int[]

Examples

Example 1

nums1 = [1,2,3,0,0,0]m = 3nums2 = [2,5,6]n = 3return = [1,2,2,3,5,6]

The valid portions are [1,2,3] and [2,5,6]. Their merged order is [1,2,2,3,5,6].

Example 2

nums1 = [1]m = 1nums2 = []n = 0return = [1]

The second array is empty, so nums1 remains unchanged.

Example 3

nums1 = [0]m = 0nums2 = [1]n = 1return = [1]

nums1 has no valid input elements. Its single position is merge capacity for the value from nums2.

Constraints

  • 0 <= m, n <= 2000.
  • 1 <= m+n <= 2000.
  • -1000000000 <= nums1[i], nums2[i] <= 1000000000.
  • nums1 has m+n entries. nums2 has n entries. The first m entries of nums1 and all entries of nums2 are nondecreasing.

More Expedia Phone Screen questions

  • Find the Shortest Round TripPHONE SCREEN · Seen Jul 2026
  • Two SumPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2024
  • Merge Two Sorted Linked ListsPHONE SCREEN · ONSITE INTERVIEW · Seen May 2023
  • Assign CookiesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • Kth Smallest Value in a BSTPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022
  • Reverse a Singly Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2022
  • Climbing StairsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2021
  • First Substring OccurrencePHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2021
  • Array Containment with MultiplicitiesPHONE SCREEN · Seen Nov 2019
  • Subtract the Next Smaller ValuePHONE SCREEN · Seen Oct 2018

Similar questions at other companies

  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Two SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Merge Sorted ArrayAmazon · ONSITE INTERVIEW
  • 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
  • Sorted Squares in Descending OrderWhatNot · PHONE SCREENWhatNot interview questions

Interview reports that mention this question

  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia New Grad SDE Oldest Loops: 4 Experiences (Part 3 of 3)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int[] mergeSortedArray(int[] nums1, int m, int[] nums2, int n) {
      // write your code here
    }
}
Checking account…