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.
defhappyLadybugs(b):#first check: no space in this string , True if they are already friends , false elseifb.count("_")<1:liste=[]foriinb:ifinotinliste:liste.append(i)res_list=list(map(lambdax:b.count(x)*x,liste))if"".join(res_list)==b:foriinb:ifb.count(i)==1:return"NO"return"YES"else:return"NO"#second check : if all the string is underscore elifb.replace("_","")=="":return"YES"#third check : if you survived the first two , one space(underscore) should be enough to validate the happy bugselse:bug_set=set(b.replace("_",""))bug_string="".join(bug_set)foriinbug_string:ifb.count(i)==1: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
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →