String Construction

  • + 0 comments

    The solution here is to count the number of unique occurrences of the characters, here is the explanation : https://youtu.be/UqqNcIUnsv8

    solution 1 : using map

    int stringConstruction(string s) {
        map<char, int> mp;
        int r = 0;
        for(int i = 0; i < s.size(); i++) if(!mp[s[i]]){
            mp[s[i]] = 1; r++;
        }
        return r;
    }
    

    solution 2 : using set

    int stringConstruction(string s) {
        set<char> se(s.begin(), s.end());
        return se.size();
    }