Problem 16

2 comments on “Problem 16”


  • Prajwal

    vector weightedUniformStrings(string s, vector q) {
    unordered_map mp;
    int new_ent=0;
    for(int i=0;i<s.size();i ++){

    if(i!=0 and s[i]==s[i-1]){
    new_ent+=s[i]-'a'+1;
    mp[new_ent]++;
    }else{
    new_ent=s[i]-'a'+1;
    mp[new_ent]++;
    }
    }
    vector ans;
    for(int i=0; i<q.size(); i++){
    if(mp[q[i]]){
    ans.push_back("Yes");
    }else{
    ans.push_back("No");
    }
    }

    return ans;
    }


  • Pratik

    def weightUniform(s, queries):
    result = []
    d = {}
    weight = 0
    for i in range(len(s)):
    if i ==0 or s[1] != s[i-1]:
    weight = ord(s[i])-96
    else:
    weight = weight+ord(s[i])-96
    d[weight] = 1

    for q in queries:
    result.append(“Yes” if q in d else “No”)
    return result