Google Interview Questions - Leetcode 929 Unique Email Addresses Fast Solution
Level: Easy


  • Every valid email has a local name and the domain name separated by @ symbol.
  • Dots in the local name are removed when checking for uniqueness.
  • any character after the + sign is ignored.
  • Domain names are left as they are to compare.


The bellow are all the same mailbox.
But the bellow is a different domain.

Solution in Python 3

This solution uses the Slice in Python to slice the string as needed and a List to store unique emails found. One major trick is to use email[i:] and not just email[i]

And the results output

class Solution:
    def numUniqueEmails(self, emails: List[str]) -> int:
        seen = []
        for email in emails:
            i = email.index('@')
            local = email[0:i]
            rest = email[i:]
            if("+" in local):
                local = local[0: local.index('+')]
            local = local.replace(".","")
            localrest = local+rest
            if localrest not in seen: 
        return len(seen)


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.