<commit_before>// Time:  O(n) for constructor, n is number of words in the dictionary. 
//        O(1) for lookup
// Space: O(k), k is number of unique words.

class ValidWordAbbr {
public:
    ValidWordAbbr(vector<string> &dictionary) {
        for (string& word : dictionary) {
            const int len = word.length();
            const string hash_val = word[0] + to_string(len - 2) + word[len - 1];
            lookup_[hash_val].emplace(word);
        }
    } 

    bool isUnique(string word) {
        const int len = word.length();
        const string hash_val = word[0] + to_string(len - 2) + word[len - 1];
        return lookup_[hash_val].empty() ||
               (lookup_[hash_val].count(word) == lookup_[hash_val].size());
    }
private:
    unordered_map<string, unordered_set<string>> lookup_;
};


// Your ValidWordAbbr object will be instantiated and called as such:
// ValidWordAbbr vwa(dictionary);
// vwa.isUnique("hello");
// vwa.isUnique("anotherWord");
<commit_msg>Update unique-word-abbreviation.cpp<commit_after>// Time:  O(n) for constructor, n is number of words in the dictionary. 
//        O(1) for lookup
// Space: O(k), k is number of unique words.

class ValidWordAbbr {
public:
    ValidWordAbbr(vector<string> &dictionary) {
        for (string& word : dictionary) {
            const string hash_val = word.front() + to_string(word.length()) + word.back();
            lookup_[hash_val].emplace(word);
        }
    } 

    bool isUnique(string word) {
        const string hash_val = word.front() + to_string(word.length()) + word.back();
        return lookup_[hash_val].empty() ||
               (lookup_[hash_val].count(word) == lookup_[hash_val].size());
    }
private:
    unordered_map<string, unordered_set<string>> lookup_;
};


// Your ValidWordAbbr object will be instantiated and called as such:
// ValidWordAbbr vwa(dictionary);
// vwa.isUnique("hello");
// vwa.isUnique("anotherWord");

{'fraction_non_alphanumeric': 0.1388028895768834, 'fraction_numerical': 0.0041279669762641896, 'mean_word_length': 2.9014084507042255, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6590448', 'n_tokens_mistral': 617, 'n_tokens_neox': 597, 'n_words': 155}