Weighted Uniform Strings

  • + 0 comments

    Python3

    def weightedUniformStrings(s, queries):
        values = set()
        values.add(ord(s[0]) - 96)
        first_value = amount = ord(s[0]) - 96
        
        for i in range(1, len(s)):
            if s[i] == s[i-1]:
                amount += first_value
                values.add(amount)
            else:
                first_value = amount = ord(s[i]) - 96
                values.add(first_value)
    
        return ['Yes' if q in values else 'No' for q in queries]