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 heredict_of_occur=dict()foriinrange(len(s)):ifs[i]indict_of_occur:dict_of_occur[s[i]]+=1else:dict_of_occur[s[i]]=1prev_var=0var_list=[]count=0deleted_element=Falseforkeyindict_of_occur:ifdict_of_occur[key]notinvar_list:ifnotdeleted_elementandcount>0and(dict_of_occur[key]-1==prev_varordict_of_occur[key]-1==0):deleted_element=Truecontinueprev_var=dict_of_occur[key]var_list.append(dict_of_occur[key])count+=1print(count,deleted_element)ifcount==1:return"YES"else:return"NO"
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 →