πŸ“ Problem Details

πŸ’­What Were My Initial Thoughts?

- create a hashset called uniqueWords
- iterate through each word in the array
	- iterate through each character in the word 
	- construct a formatted string , following the defined rules
	- once we encounter an '@', push the remaining substr immediately into the formatted string
	- insert the formatted string into the hashset if it doesnt already exist
- return the hashsets size 

πŸ€”What Did I Struggle With?

~

πŸ’‘ Explanation of Solution

same as initial thoughts

βŒ› Complexity Analysis

Time Complexity: O(n * k)
	where n is the number of emails 
	and k is the number of characters in an email

Space Complexity: O(k) used to store a formatting string with a max size of k characters

πŸ’» Implementation of Solution

class Solution {
public:
    int numUniqueEmails(vector<string>& emails) {
        
        unordered_set<string> uniqueWords;
        
        for(const auto email : emails) {
            string formattedWord;
            bool ignoreChars = false;
 
            for(int i=0; i < email.size(); i++) {
 
                if(email[i] == '@') {
                    formattedWord += email.substr(i); 
                    break;
                }
 
                if(ignoreChars) continue;
                if(email[i] == '.') continue;
                if(email[i] == '+'){
                    ignoreChars = true;
                    continue;
                }
 
                formattedWord += email[i];
            }
 
            if(uniqueWords.find(formattedWord) == uniqueWords.end())
                uniqueWords.insert(formattedWord);
        }
 
        return uniqueWords.size();
    }
};