I knew the general idea but fumbled on the order of operations at first.
Start by clarifying the canonicalization rules and edge cases (e.g., multiple '+' signs, dots in domain, case sensitivity). Then outline an algorithm that splits each email into local and domain parts, applies the transformations to the local part, and uses a hash set to count unique canonical forms. Finally, discuss time/space complexity and potential trade-offs.
Pro tip: Mention that you would handle edge cases like empty local part after stripping, and consider whether the domain should be lowercased (often domains are case-insensitive). Also, note that using a set gives O(n) time and space, which is optimal.
Ask about case sensitivity, multiple '+' signs, dots in domain, and invalid emails. Confirm that only the first '+' and all dots in the local part are removed.
Split the email at '@' into local and domain. In the local part, remove everything from the first '+' onward, then remove all dots. Leave the domain unchanged (or lowercase if specified).
Use a hash set to store canonical emails, then return its size. This gives O(1) average insertion and O(n) overall time.
Discuss time O(n * m) where m is average email length, and space O(n). Mention alternatives like sorting but note set is simpler and faster.
Walk through a few examples, including edge cases like 'a.b+c@domain.com' and 'a.b@domain.com' to show they canonicalize to the same address.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.