Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Unique Elements From Two Sorted Arrays

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

Your question is Unique Elements From 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

FuboTV receives two sorted lists of content IDs from different catalog feeds. Return the values that appear in exactly one list, preserving ascending order.

Implement unique_elements(first, second) using the sorted order to achieve linear time. Each input list contains distinct integers, and the output must also be sorted with no duplicates.

Formal Specification

  • Input: Two lists of distinct integers, first and second, sorted in strictly increasing order.
  • Output: A list containing every integer present in exactly one of the two input lists, sorted in strictly increasing order.
  • Values appearing in both lists must be excluded.

Constraints

  • 0 <= len(first), len(second) <= 10^5
  • -10^9 <= first[i], second[i] <= 10^9
  • Each input list contains distinct values
  • Both lists are sorted in strictly increasing order

Function Signature

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