You are viewing a single comment's thread. Return to all comments →
Python 3
import string import itertools def weightedUniformStrings(s, queries): alpha = string.ascii_lowercase weights = dict(zip(alpha, itertools.count(1))) groups = (g for k, g in itertools.groupby(s)) U = set() for group in groups: substr_weights = (weights[c] for c in group) substr_U = itertools.accumulate(substr_weights) U.update(substr_U) yes_no = {True:"Yes", False: "No"} return [yes_no[q in U] for q in queries]
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
Python 3