Weighted Uniform Strings

  • + 0 comments

    Simple C++ Solution, video here : https://youtu.be/xhpzPQBB9ts

    vector<string> weightedUniformStrings(string s, vector<int> queries) {
        // build the set
        map<int, int> mp;
        int last = 0;
        for(int i = 0; i < s.size(); i++){
            if(i != 0 && s[i] == s[i-1]){
                last += s[i] - 'a' + 1;
                mp[last] = 1;
            }
            else{
                last = s[i] - 'a' + 1;
                mp[last] = 1;
            }
        }
        vector<string>result;
        for(int i = 0; i < queries.size(); i++){
            if(mp[queries[i]]) result.push_back("Yes");
            else result.push_back("No");
        }
        return result;
        
    }