Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Array Common Elements
00:00
5 left

Array Common Elements

EasyPython

Problem

A Cloudera Data Platform processing component receives two batches of integer identifiers and needs to determine which identifiers appear in both batches. Return the unique common elements, preserving the order in which they first appear in nums1.

Implement a function that does not modify either input array.

Formal Specification

Given two arrays of integers, nums1 and nums2, return an array containing every distinct value that occurs at least once in both arrays. The result must follow nums1's first-occurrence order. If there are no common values, return an empty array.

Constraints

  • 0 <= len(nums1), len(nums2) <= 10^5
  • -10^9 <= nums1[i], nums2[i] <= 10^9
  • Duplicate values may appear in either array.
  • The output must contain unique values in nums1 first-occurrence order.

Function Signature

def common_elements(nums1, nums2):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.