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.
defisValid(s):# Write your code heredata={}foriins:ifiindata.keys():data[i]+=1else:data[i]=1temp=list(data.values())# if all the characters except one appears same numer of time (e.g aabbccd)iftemp.count(max(temp))==len(data.keys())-1andtemp.count(1)==1:return"YES"# contains counts of each charactercheck=min(list(data.values()))#subtractminimumfromeachcountforiindata.keys():data[i]=data[i]-checktemp=list(data.values())# if all count become 0 except one return YESif(temp.count(0)==len(data.keys())-1)andtemp.count(1)==1:return"YES"# if all become 0 except return YESeliftemp.count(0)==len(data.keys()):return"YES"else:return"NO"#elsereturnNO
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →