Approach 1: Canonical Form

Intuition and Algorithm

For each email address, convert it to the canonical address that actually receives the mail. This involves a few steps:

  • Separate the email address into a local part and the rest of the address.

  • If the local part has a '+' character, remove it and everything beyond it from the local part.

  • Remove all the zeros from the local part.

  • The canonical address is local + rest.

After, we can count the number of unique canonical addresses with a Set structure.

Complexity Analysis

  • Time Complexity: , where is the total content of emails.

  • Space Complexity: .

Analysis written by: @awice.