Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge and Sort Two Arrays

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

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

Leidos mission software may receive integer readings from two unsynchronized sources. Implement a function that combines two unsorted arrays and returns every value in nondecreasing order.

You should sort each input array, then merge the sorted results with two pointers. Return a new array and do not modify either input array. Duplicate values must be preserved.

Formal Specification

Given two arrays arr1 and arr2 of integers, return a new array containing all elements from both arrays in ascending order. The function must support empty arrays and negative values.

Constraints

  • 0 <= len(arr1), len(arr2) <= 10^5
  • -10^9 <= arr1[i], arr2[i] <= 10^9
  • The result contains exactly len(arr1) + len(arr2) elements
  • Neither input array may be modified

Function Signature

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