Weighted Uniform Strings

  • + 0 comments

    Pythonic:

    def weightedUniformStrings(s, queries):
        mem = accumulate(range(1, len(s)), lambda c, i: c+1 if s[i] == s[i-1] else 1, initial=1)
        mem = set(m[1] *(ord(m[0]) - 96) for m in zip(s, mem))
        
        return ['Yes' if q in mem else 'No' for q in queries]