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.
defcalculate(n,b):# if b.count("_") == 0 and compare(b):# find if exists any single letterifb.count("_")==0andlen(re.sub(r'((.)\2+)',"",b))!=0:return"NO"forainset(b):ifa!="_"andb.count(a)==1:return"NO"return"YES"'''Thanks to reddeadya, this part didn't work for "XXBBXX"def compare(b): if len(b) == 1: return True for x in set(b): if x * b.count(x) != b[b.index(x):b.index(x) + b.count(x)]: return True return False'''for_inrange(int(input())):n=int(input())b=input()print(calculate(n,b))
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
Python 3: