Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge Two Sorted Arrays

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

Your question is Merge 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

Given two sorted integer arrays arr1 and arr2, write a function that returns a new sorted array containing all elements from both arrays. The input arrays are already sorted in non-decreasing order, and duplicate values should be preserved in the result.

Constraints

  • 0 <= len(arr1), len(arr2) <= 10^5
  • -10^9 <= arr1[i], arr2[i] <= 10^9
  • Both input arrays are sorted in non-decreasing order

Function Signature

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