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 herestringDict={}forletterins:stringDict[letter]=stringDict.get(letter,0)+1dictValues=list(stringDict.values())isRemovedOne=Falseforiinrange(1,len(dictValues)):diff=abs(dictValues[i]-dictValues[i-1])ifdiff==0:continueelse:ifnotisRemovedOne:isRemovedOne=TruedictValues[i]-=1else:return"NO"return"YES"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →
Python Solution using a dictionary: