Customers who came back

hashing

Customers who came back

Target Python Interview Question

Target's loyalty team wants to thank customers who shopped in both January and February. Each month's list holds one customer ID per order, so a customer can appear more than once.

Write a function repeat_customers(january_ids, february_ids) that returns a list of the customer IDs that appear in both lists. Each ID should appear once in the answer, and the IDs can be in any order.

Asked of

  • Data Engineer
  • Data Scientist
  • Analytics Engineer
  • ML Engineer
  • AI Engineer

Example 1

Input

repeat_customers([101, 102, 103, 101], [103, 104, 101])

Output

[101, 103]

Example 2

Input

repeat_customers([5, 6], [7, 8])

Output

[]

Explanation

Customer 101 ordered twice in January and again in February, and customer 103 ordered in both months, so the answer holds 101 and 103, each once. Customer 102 only ordered in January and customer 104 only in February, so neither is included.

Submit also runs 3 hidden test cases that check edge cases.