Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Common Numbers Between Lists

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

Your question is Common Numbers Between Lists. 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

Gemini QA tooling compares value lists from two test surfaces, such as Gemini app results and Gemini API results. Given two integer lists, return the distinct values present in both lists, ordered by their first appearance in the first list.

Formal Specification

Implement common_numbers(nums1, nums2).

  • Input: nums1 and nums2, two lists of integers.
  • Output: A list containing each distinct integer that appears in both inputs.
  • Preserve the order in which values first appear in nums1.
  • Include each shared value at most once.
  • Do not modify either input list.
  • Return an empty list when there are no common values.

Constraints

  • 0 <= len(nums1), len(nums2) <= 10^5
  • -10^9 <= nums1[i], nums2[i] <= 10^9
  • The input lists may contain duplicates
  • The result preserves the first appearance order from nums1
  • Neither input list may be modified

Function Signature

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