Every valid email consists of a local name and a domain name, separated by the
-
For example, in
"alice@cscode.io" ,"alice" is the local name, and"cscode.io" is the domain name.
If you add periods
-
For example,
"alice.z@cscode.io" and"alicez@cscode.io" forward to the same email address.
If you add a plus
-
For example,
"m.y+name@email.com" will be forwarded to"my@email.com" .
It is possible to use both of these rules at the same time.
Given an array of strings
Output: 2
Explanation: "user.jc@cscode.io" and "u.s.e.r.jc+test@cscode.io" will become "userjc@cscode.io" after you ignore "." and all characters after "+" symbol. and "user.jc+test@cs.code.io" will become "userjc@cs.code.io" which has different domain name.
Contents
Solution using HashSet, after applying rules
In this approach, we are going to first apply rules given in the problem statement, then store resultant email addresses in a
Rules given are:
-
If the email's local name part, ignore
'.' symbols, if there are any. -
In the email's local name part, ignore all characters after
'+' symbol, if it is there. -
In the email address, take all characters after
'@' symbol.
Complexity Analysis:
Time complexity: Above code runs in O(n * m) time where
Space complexity: O(n).
Above implementations source code can be found at