FastPrepMerge Two Sorted Arrays
Problems/Merge Two Sorted Arrays

Merge Two Sorted Arrays

Zillow logoZillow● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow by a Sr. Software Engineer candidate in San Francisco who interviewed in April 2019, posted the report in June 2021 and accepted an offer. The process lasted a week. The report names the task, merging two sorted arrays, and also names merge sort, which we keep as a separate question.

The report does not say which round asked the task, whether the merge had to happen inside one of the arrays or in a new one, how much extra memory was allowed, what limits applied, or whether there were follow-ups. Our choices: the function mergeSortedArrays gets the integer arrays nums1 and nums2, each sorted in non-decreasing order, and returns a new sorted array that holds every value of both; either array may be empty. The limits (up to 100,000 values per array, each from -1,000,000,000 to 1,000,000,000) are ours as well. With no round named, we place the task in a phone screen; that placement is our reading.

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

You get two integer arrays, nums1 and nums2. Within each array the values never go down from left to right (non-decreasing order): every value is less than or equal to the value after it.

Build a single array in non-decreasing order that holds every value of both arrays. A value keeps every copy it has in the two arrays, so the returned array has nums1.length + nums2.length values.

One or both arrays can have length 0.

Function

mergeSortedArrays(nums1: int[], nums2: int[]) → int[]

Examples

Example 1

nums1 = [2,5]nums2 = [1,5]return = [1,2,5,5]

The smallest value overall is 1, from nums2; next is 2, from nums1. Each input holds one 5, so the answer ends with two copies of 5.

Example 2

nums1 = []nums2 = [4,6]return = [4,6]

With nums1 empty, the returned array equals nums2.

Example 3

nums1 = [-3,0,0,8]nums2 = [-5,0,9]return = [-5,-3,0,0,0,8,9]

The three copies of 0 all stay, two taken from nums1 plus one taken from nums2; the returned array has 4 + 3 = 7 values.

Constraints

  • 0 <= nums1.length, nums2.length <= 105
  • -109 <= nums1[i], nums2[j] <= 109
  • nums1 and nums2 are each sorted in non-decreasing order.

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
  • Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Jump GamePHONE SCREEN · Seen Dec 2022
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
  • Employee Free TimePHONE SCREEN · Seen Oct 2022
  • First Unique Character in a StringPHONE SCREEN · Seen Oct 2022

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 Sorted Arrays with DuplicatesMygate · PHONE SCREENMygate interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int[] mergeSortedArrays(int[] nums1, int[] nums2) {
        // Write your code here.
    }
}
Checking account…