Weighted Uniform Strings

  • + 7 comments

    c++

    
    
    set<int> weight;
    int count = 1;
    for (int i = 0; i < s.size(); ++i) {
        int currentWeight = (s[i] - 'a' + 1);
        if (i > 0 && s[i] == s[i - 1]) {
            count++;
        } else {
            count = 1;
        }
        weight.insert(count * currentWeight);
    }
    vector<string> result;
    for (int q : queries) {
        if (weight.find(q) != weight.end()) {
            result.push_back("Yes");
        } else {
            result.push_back("No");
        }
    }
    return result;
    

    }