Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Combine Two Sorted Arrays

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Combine Two Sorted Arrays. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Akamai Edge DNS can produce sorted metric batches from separate edge-processing streams. Given two arrays of integers sorted in nondecreasing order, merge them into one sorted array.

Return a new array containing every value from both input arrays, including duplicates. Do not call a sorting function on the combined values.

Formal Specification

Implement merge_sorted_arrays(nums1, nums2):

  • Input: two Python lists of integers, nums1 and nums2, each sorted in nondecreasing order.
  • Output: a new Python list containing all values from nums1 and nums2, sorted in nondecreasing order.
  • The input arrays may have different lengths, and either array may be empty.

Constraints

  • 0 <= len(nums1), len(nums2) <= 10^5
  • -10^9 <= nums1[i], nums2[j] <= 10^9
  • Both input arrays are sorted in nondecreasing order
  • The result contains all values, including duplicates
  • Neither input array may be modified

Function Signature

def merge_sorted_arrays(nums1, nums2):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output