Weighted Uniform Strings

  • + 0 comments

    Python 3

    def weightedUniformStrings(s, queries):
        alphabet = "_abcdefghijklmnopqrstuvwxyz"
        alphabet = {i:alphabet.index(i) for i in alphabet}
        weights = set()
        previous = ""
        length = 0
        for letter in s:
            if previous == letter:
                length += 1
                weights.add(alphabet[letter] * length)
            else:
                previous = letter
                length = 1
                weights.add(alphabet[letter])
        return list(map(lambda x: "Yes" if x in weights else "No", queries))