✅ 90% beatable || JS Sol. || Explained with Approach ✅
\n\n# Approach\n Describe your approach to solving the problem. \n\nThe algorithm uses a Set to store unique email addresses and then iterates through the array
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nThe algorithm uses a **Set** to store *unique email addresses* and then iterates through the *array of email addresses*.\n\n- For each email address, it performs the following steps:\n\n1. Split the email address into local and domain parts using the **"@"** symbol.\n\n2. Remove any dots **(".")** from the local part of the email address.\n\n3. Find the index of the first **"+"** symbol in the local part of the email address, if it exists.\n\n4. If a **"+"** symbol is found, remove all characters after it in the local part.\n\n5. Add the modified email address **(local@domain)** to the **Set**.\n\n6. Finally, the algorithm returns the size of the **Set**, which represents the **number of unique email addresses**.\n\n- The approach works because it effectively removes any characters in the local part of the email address that do not affect its uniqueness. \n\n- By doing this, it ensures that each unique email address is only added to the *Set* once, even if it appears in the input array multiple times with different variations.\n\n\n\n# Complexity\n- Time complexity: $$O(n*m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n1. Here **n** is the number of email addresses and **m** is the length of the longest email address. \n\n2. This is because the algorithm loops through each email address and performs operations that take O(m) time (e.g. splitting the email address into local and domain parts, replacing dots, etc.). \n\n3. The set operation to add an email address to the set has an amortized time complexity of O(1).\n\n\n\n\n- Space complexity: $$O(n*m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n1. This is because the set used to store unique email addresses can potentially store up to n unique email addresses, each with a maximum length of m.\n\n2. Additionally, the local and domain variables created during each iteration also have a maximum length of m. \n\n3. Therefore, the total space used by this algorithm is proportional to **nm**.\n\n\n\n\n\n\n\n# Code\n```\n/**\n * @param {string[]} emails\n * @return {number}\n */\n \nvar numUniqueEmails = function(emails) {\n    \n    let uniqueEmails = new Set();  // to store unique email addresses\n    \n    for (let email of emails) {\n        \n        let [local, domain] = email.split(\'@\');  // split local and domain parts\n\n        local = local.replace(/\\./g, \'\');  // remove dots from local part\n\n        let plusIndex = local.indexOf(\'+\');  // find index of plus sign\n\n            if (plusIndex !== -1) {\n                \n                local = local.substring(0, plusIndex); // remove everything after plus sign\n            }\n            \n            uniqueEmails.add(local + \'@\' + domain); // add modified email to set\n    }\n    \n    return uniqueEmails.size; // return number of unique email addresses\n  \n};\n```\n\n![cat img for upvote on LC.jpeg](https://assets.leetcode.com/users/images/242bd8b8-8a1a-4bd6-b87f-9d290d6548ab_1678033187.7374706.jpeg)\n
['Array', 'Hash Table', 'String', 'JavaScript']