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.
Appending to list was creating multiple repeated values.
Adding to set instead of appending to list solved my problem.
This is the only difference in both the codes i have provided.
Code With Timeout Error
#!/bin/python3importsyss=input().strip()n=int(input().strip())seq=[]fornuminrange(1,27):seq.append(0)forxinsorted(set(s)):i=1;whilex*iins:i+=1seq[ord(x)-97]=i-1finale=[]#using listforindex,everyinenumerate(seq):forsvalinrange(every):finale.append((index+1)*(sval+1))#using list fora0inrange(n):x=int(input().strip())print("Yes"ifxinfinaleelse"No")
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
Language: Python
Possible reason for Timeout Error
Appending to list was creating multiple repeated values.
Adding to set instead of appending to list solved my problem.
This is the only difference in both the codes i have provided.
Code With Timeout Error
Code Without Timeout Error
Hope it helps!