Google Leetcode 929 Unique Email Addresses

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

Analysis

  • 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.

Example

The bellow are all the same mailbox.
testme@example.com
test.me@example.com
test.me+hey@example.com
test.me+jo@example.com
test.me+ee@example.com
But the bellow is a different domain.
testme@examplex.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]

Quick Steps and Scenarios Overview

What You Need to DoQuick Jump
AnalysisJump to Step 1
ExampleJump to Step 2
Solution in Python 3Jump to Step 3

And the results output

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)

Helpful Tips

Check all labels, connections, and power ratings before starting so everything fits safely and securely. If any detail looks slightly different on your model, pause the embedded video above for a clear closeup view.


Comments

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.