Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Merge Two Sorted Arrays
00:00
5 left

Merge Two Sorted Arrays

EasyPython

Problem

Given two arrays of integers nums1 and nums2, both sorted in non-decreasing order, return a new array containing all elements from both arrays in non-decreasing order. The function should preserve duplicates and handle empty arrays correctly.

Constraints

  • 0 <= len(nums1), len(nums2) <= 10^5
  • -10^9 <= nums1[i], nums2[i] <= 10^9
  • nums1 and nums2 are each sorted in non-decreasing order

Function Signature

def merge_sorted_arrays(nums1, nums2):
Interviewer

Your question is Merge Two Sorted Arrays. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.