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):# Write your code heretemp={}under_score_present=Falsealready_happy=Truen=len(b)foriinrange(n):ifb[i]=="_":under_score_present=Truecontinueifalready_happy:happy_left=Trueifi>0andb[i]==b[i-1]elseFalsehappy_right=Trueifi<(n-1)andb[i]==b[i+1]elseFalseifnot(happy_leftorhappy_right):already_happy=Falseiftemp.get(b[i]):temp[b[i]]+=1else:temp[b[i]]=1foriintemp:iftemp[i]==1:return"NO"return"YES"ifunder_score_presentoralready_happyelse"NO"
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 →