Hone logo
Hone
Problems

Find Duplicate Emails in a Contact List

Imagine you're building a contact management system. A common issue is having multiple entries for the same person due to accidental duplicate entries with identical email addresses. This challenge asks you to identify and report these duplicate email addresses, ensuring your system can efficiently manage and de-duplicate contacts.

Problem Description

You are given a list of contacts, where each contact has a unique ID and an email address. Your task is to find all email addresses that appear more than once in the list. The output should be a list of these duplicate email addresses.

Key Requirements:

  • Identify email addresses that are associated with more than one contact.
  • Return a list of only the email addresses that are duplicates.
  • Each duplicate email address should appear only once in the output list, even if it appears three or more times in the input.

Expected Behavior:

If an email address is present in the input list for two or more contacts, it should be included in the output list. If an email address is unique (present for only one contact), it should not be included.

Edge Cases:

  • An empty input list.
  • A list with no duplicate email addresses.
  • A list where all email addresses are duplicates.
  • Email addresses are case-sensitive. "example@domain.com" is different from "Example@domain.com".

Examples

Example 1:

Input:
[
  { id: 1, email: "alice@example.com" },
  { id: 2, email: "bob@example.com" },
  { id: 3, email: "alice@example.com" }
]

Output:
["alice@example.com"]

Explanation: The email address "alice@example.com" appears for two contacts (ID 1 and ID 3), making it a duplicate. "bob@example.com" is unique.

Example 2:

Input:
[
  { id: 101, email: "charlie@domain.net" },
  { id: 102, email: "david@domain.net" },
  { id: 103, email: "eve@domain.net" },
  { id: 104, email: "charlie@domain.net" },
  { id: 105, email: "eve@domain.net" }
]

Output:
["charlie@domain.net", "eve@domain.net"]

Explanation: "charlie@domain.net" appears twice and "eve@domain.net" appears twice, so both are duplicates. "david@domain.net" is unique.

Example 3:

Input:
[
  { id: 201, email: "frank@mail.org" },
  { id: 202, email: "grace@mail.org" }
]

Output:
[]

Explanation: Both email addresses are unique, so the output list is empty.

Constraints

  • The input list will contain between 0 and 1000 contacts.
  • Each contact will have an id (integer) and an email (string).
  • Email addresses will be strings conforming to a standard email format, but could potentially be empty strings (though this is unlikely for valid contacts).
  • Your solution should aim for an efficient time complexity, ideally better than O(n^2) where n is the number of contacts.

Notes

Consider how you can efficiently keep track of email addresses you've already seen and how many times you've seen them. Data structures like hash maps or dictionaries are often very useful for this type of problem. Remember to handle the requirement of returning each duplicate email only once.

Loading editor...
plaintext