Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Combining Arrays Into Sorted Output

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

Your question is Combining Arrays Into Sorted Output. 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

Meta's Scuba-style observability workflows may receive event identifiers from two unsorted sources with different batch sizes. Implement a function that combines both arrays and returns all values in nondecreasing order.

Formal Specification

Given two arrays first and second of integers, return a new array containing every element from both inputs exactly once per occurrence, sorted from smallest to largest. The input arrays may have different lengths and may be empty. Do not modify either input array.

Your solution should use an appropriate comparison-based sorting approach and should handle duplicate and negative values.

Constraints

  • 0 <= len(first), len(second) <= 10^5
  • len(first) + len(second) >= 1
  • -10^9 <= first[i], second[i] <= 10^9
  • Neither input array may be modified
  • Return a new array

Function Signature

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