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.
def weightedUniformStrings(s, queries):
# Write your code here
U=set()
count={}
res=[]
for i in range(len(s)):
ch=s[i]
if ch in count.keys():
count.update({ch:count[ch]+1})
else:
count.update({ch:1})
weight=((ord(ch)-ord("a"))+1)*count[ch]
U.add(weight)
if s[i]!=s[-1]:
ch_next=s[i+1]
if ch!=ch_next:
count[ch]=0
for q in queries:
if q in U:
res.append("Yes")
else:
res.append("No")
return res**
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 →
def weightedUniformStrings(s, queries): # Write your code here U=set() count={} res=[] for i in range(len(s)): ch=s[i]