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. firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org
But the bellow is a different domain. email@example.com
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: seen.append(localrest) return len(seen)