Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Array Intersection Implementation

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

Your question is Array Intersection Implementation. 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

Piping Rock Health Products receives product identifier lists from two fulfillment workflows. Given two integer arrays, return the distinct identifiers that appear in both arrays, preserving the order of their first appearance in arr1.

Formal Specification

Implement find_intersection(arr1, arr2), where arr1 and arr2 are arrays of integers. Return a new array containing each common value exactly once. The result must follow the order established by the first occurrence of each value in arr1.

Do not modify either input array. If the arrays have no common values, return an empty array.

Constraints

  • 0 <= len(arr1), len(arr2) <= 100,000
  • -10^9 <= arr1[i], arr2[i] <= 10^9
  • Each output value must be distinct
  • Preserve first-occurrence order from arr1
  • Do not modify the input arrays

Function Signature

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