We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
**python **
def weightedUniformStrings(s, queries):
"""
Determines if each query value is a valid weight of a substring in the given string.
Args:
s (str): The input string.
queries (list): A list of query values.
Returns:
list: A list of "Yes" or "No" for each query, indicating whether the query value is a valid weight.
"""
weights = set()
weight = ord(s[0]) - 96
weights.add(weight)
for i in range(1, len(s)):
if s[i] == s[i - 1]:
weight += ord(s[i]) - 96
else:
weight = ord(s[i]) - 96
weights.add(weight)
return ["Yes" if q in weights else "No" for q in queries]
if name == 'main':
s = input()
queries_count = int(input().strip())
queries = []
for _ in range(queries_count):
queries_item = int(input().strip())
queries.append(queries_item)
result = weightedUniformStrings(s, queries)
print('\n'.join(result))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
**python ** def weightedUniformStrings(s, queries): """ Determines if each query value is a valid weight of a substring in the given string.
if name == 'main': s = input() queries_count = int(input().strip())