✅Explained Step by Step | Video | List Most Common Array Interview Problems✅
https://youtu.be/TC_xLIWl7qY?si=9Zxc3XqkkB2T1UU3\n\npython3 []\nclass Solution:\n    def numUniqueEmails(self, emails: List[str]) -> int:\n        unique_emails
https://youtu.be/TC_xLIWl7qY?si=9Zxc3XqkkB2T1UU3\n\n```python3 []\nclass Solution:\n    def numUniqueEmails(self, emails: List[str]) -> int:\n        unique_emails = set()\n        for email in emails:\n            local, domain = email.split(\'@\')\n            local = local.split(\'+\')[0]\n            local = local.replace(\'.\', \'\')\n            unique_emails.add((local, domain))\n        return len(unique_emails)\n```\n```cpp []\nclass Solution {\npublic:\n    int numUniqueEmails(vector<string>& emails) {\n        set<pair<string, string>> uniqueEmails;\n        \n        for (const string& email : emails) {\n            size_t atPos = email.find(\'@\');\n            string local = email.substr(0, atPos);\n            string domain = email.substr(atPos + 1);\n            \n            size_t plusPos = local.find(\'+\');\n            if (plusPos != string::npos) {\n                local = local.substr(0, plusPos);\n            }\n            \n            local.erase(remove(local.begin(), local.end(), \'.\'), local.end());\n            uniqueEmails.insert({local, domain});\n        }\n        \n        return uniqueEmails.size();\n    }\n};\n```\n```java []\nclass Solution {\n    public int numUniqueEmails(String[] emails) {\n        Set<String> uniqueEmails = new HashSet<>();\n        \n        for (String email : emails) {\n            String[] parts = email.split("@");\n            String local = parts[0];\n            String domain = parts[1];\n            \n            local = local.split("\\\\+")[0];\n            local = local.replace(".", "");\n            \n            uniqueEmails.add(local + "@" + domain);\n        }\n        \n        return uniqueEmails.size();\n    }\n}\n```\n```csharp []\npublic class Solution {\n    public int NumUniqueEmails(string[] emails) {\n        var uniqueEmails = new HashSet<string>();\n        \n        foreach (string email in emails) {\n            string[] parts = email.Split(\'@\');\n            string local = parts[0];\n            string domain = parts[1];\n            \n            local = local.Split(\'+\')[0];\n            local = local.Replace(".", "");\n            \n            uniqueEmails.Add($"{local}@{domain}");\n        }\n        \n        return uniqueEmails.Count;\n    }\n}\n```\n```golang []\nfunc numUniqueEmails(emails []string) int {\n    uniqueEmails := make(map[string]bool)\n    \n    for _, email := range emails {\n        parts := strings.Split(email, "@")\n        local, domain := parts[0], parts[1]\n        \n        if plusIndex := strings.Index(local, "+"); plusIndex != -1 {\n            local = local[:plusIndex]\n        }\n        \n        local = strings.ReplaceAll(local, ".", "")\n        uniqueEmails[local+"@"+domain] = true\n    }\n    \n    return len(uniqueEmails)\n}\n```\n```swift []\nclass Solution {\n    func numUniqueEmails(_ emails: [String]) -> Int {\n        var uniqueEmails = Set<String>()\n        \n        for email in emails {\n            let parts = email.split(separator: "@")\n            var local = String(parts[0])\n            let domain = String(parts[1])\n            \n            if let plusIndex = local.firstIndex(of: "+") {\n                local = String(local[..<plusIndex])\n            }\n            \n            local = local.replacingOccurrences(of: ".", with: "")\n            uniqueEmails.insert(local + "@" + domain)\n        }\n        \n        return uniqueEmails.count\n    }\n}\n```\n```javascript [JS]\n// JavaScript\n\nvar numUniqueEmails = function(emails) {\n    const uniqueEmails = new Set();\n    \n    for (const email of emails) {\n        const [local, domain] = email.split(\'@\');\n        const cleanLocal = local.split(\'+\')[0].replace(/\\./g, \'\');\n        uniqueEmails.add(`${cleanLocal}@${domain}`);\n    }\n    \n    return uniqueEmails.size;\n};\n```\n```typescript [TS]\n// TypeScript\n\nfunction numUniqueEmails(emails: string[]): number {\n    const uniqueEmails = new Set<string>();\n    \n    for (const email of emails) {\n        const [local, domain] = email.split(\'@\');\n        const cleanLocal = local.split(\'+\')[0].replace(/\\./g, \'\');\n        uniqueEmails.add(`${cleanLocal}@${domain}`);\n    }\n    \n    return uniqueEmails.size;\n}\n```\n```rust []\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn num_unique_emails(emails: Vec<String>) -> i32 {\n        let mut unique_emails = HashSet::new();\n        \n        for email in emails {\n            let parts: Vec<&str> = email.split(\'@\').collect();\n            let mut local = parts[0].to_string();\n            let domain = parts[1].to_string();\n            \n            if let Some(plus_idx) = local.find(\'+\') {\n                local.truncate(plus_idx);\n            }\n            \n            local = local.replace(".", "");\n            unique_emails.insert(format!("{}@{}", local, domain));\n        }\n        \n        unique_emails.len() as i32\n    }\n}\n```\n```ruby []\ndef num_unique_emails(emails)\n    unique_emails = Set.new\n    \n    emails.each do |email|\n        local, domain = email.split(\'@\')\n        local = local.split(\'+\')[0]\n        local = local.delete(\'.\')\n        \n        unique_emails.add("#{local}@#{domain}")\n    end\n    \n    unique_emails.size\nend\n```\n\n\n### Complexity\n- Time complexity: O(n)\n\n\n\n\n- Space complexity: O(n)\n\n\n\n\n# Explanation\n\n\n \n\n\n---\n\n\n1. Initialize a Set for Unique Emails:`unique_emails = set()`\n- A set called unique_emails is created to store unique email addresses as tuples. Sets are used here because they automatically handle duplicates (only unique items are stored).\n\n2. Loop Through Each Email:`for email in emails:`\n- For each email in the input list emails, the method performs the following steps to normalize the email address.\n3. Split the Email Address:`local, domain = email.split(\'@\')`\n- The email is split into two parts: `local` (the part before `@`) and `domain` (the part after `@`).\n4. Process the Local Part:`local = local.split(\'+\')[0]`\n\n- If there is a `+` in the `local` part, everything after the `+` is ignored by taking only the part before the `+`. This is because anything after `+` in the local part is considered irrelevant according to the problem.\n\n5. Remove Periods in the Local Part:`local = local.replace(\'.\', \'\')`\n- All periods . are removed from the local part, as they do not affect the actual email address.\n\n6. Add the Processed Email to the Set:`unique_emails.add((local, domain))`\n- The processed `local` and `domain` parts are combined into a tuple and added to `unique_emails`. The set ensures that only unique email addresses are kept.\n\n7. Return the Count of Unique:`Emails:return len(unique_emails)`\n\n- Method returns the number of unique email addresses by taking the length of the `unique_emails` set.\n\n\n---\n![array2.png](https://assets.leetcode.com/users/images/7a0a6937-9d07-4cf6-ad93-d27ffcaf69a0_1730577425.4474297.png)\n# Most common Array Interview Problems\nList based on my research (interviews, reddit, github) Probably not 100% accurate but very close to my recruitments. Leetcode Premium is probably more accurate [I don\'t have]\n\n\n**Easy:** [[1. Two Sum]](https://leetcode.com/problems/two-sum/solutions/5999466/beats-100-explained-step-by-step-list-most-common-array-inverview) **(common warm-up)** [[121. Best Time to Buy and Sell Stock]](https://leetcode.com/discuss/topic/6027720/solution/) [[88. Merge Sorted Array]](https://leetcode.com/problems/merge-sorted-array/solutions/6031394/beats-100-explained-step-by-step-list-most-common-string-interview-problems) [[27. Remove Element]](https://leetcode.com/problems/remove-element/solutions/6031528/beats-100-explained-step-by-step-list-most-common-array-interview-problems) [[929. Unique Email Addresses]](https://leetcode.com/problems/unique-email-addresses/solutions/6031687/explained-step-by-step-video-list-most-common-array-interview-problems) \n\n\n**Medium/Hard:** [[15. 3Sum]](https://leetcode.com/problems/3sum/description/) [[42. Trapping Rain Water]](https://leetcode.com/problems/trapping-rain-water/?envType=problem-list-v2&envId=atbyk0mj) [[56. Merge Intervals]](https://leetcode.com/problems/merge-intervals/description/) [[57. Insert Interval]](https://leetcode.com/problems/insert-interval/description/) [[46. Permutations]](https://leetcode.com/problems/permutations/description/) [[53. Maximum Subarray]](https://leetcode.com/problems/maximum-subarray/description/) [[73. Set Matrix Zeroes]](https://leetcode.com/problems/set-matrix-zeroes/description/) [[284. Peeking Iterator]](https://leetcode.com/problems/peeking-iterator/description/)\n\n\n####  [Interview Questions and Answers Repository](https://github.com/RooTinfinite/Interview-questions-and-answers)\n\n# Interview Priorities\n\n\n| Patterns                | Difficulty | Interview Frequently           |\n|----------------------|---------------------|----------------------|\n| **Basic [Array](https://leetcode.com/problems/two-sum/solutions/5999466/beats-100-explained-step-by-step-list-most-common-array-inverview) / [String](https://leetcode.com/problems/valid-parentheses/solutions/6013115/solution)**                 | **Easy**              | **Very High**               |\n| **Two Pointers**         | **Easy**                | **High**                 |\n| **Sliding Window**       | **Easy**                | **High**                 |\n| **Breadth-First Search** | **Easy**                | **High**                 |\n| **Depth-First Search**   | **Medium**              | **High**                 |\n| **[Backtracking](https://leetcode.com/problems/letter-combinations-of-a-phone-number/solutions/5976064/complex-backtracking-interview-prepare-list-of-backtracking-questions-beats-100)**         | **High**                | **High**                 |\n| Heap                 | Medium              | Medium               |\n| Binary Search        | Easy                | Medium               |\n| [Dynamic Programming](https://leetcode.com/problem-list/atwflvk7/)  | High                | Medium               |\n| Divide and Conquer   | Medium              | Low                  |\n| Trie                 | Medium              | Low                  |\n| Union Find           | Medium              | Low                  |\n| Greedy               | High                | Low                  |\n\n\n\n\n\n\n\n\n\n\n![image.png](https://assets.leetcode.com/users/images/9dc1b265-b175-4bf4-bc6c-4b188cb79220_1728176037.4402142.png)\n\n\n\n\n
['Swift', 'C++', 'Java', 'Go', 'TypeScript', 'Python3', 'Rust', 'Ruby', 'JavaScript', 'C#']