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.
fromcollectionsimportCounterdefhappyLadybugs(b):# Write your code hereiflen(b)==1andb[0]=='_':return'YES'iflen(b)==1andb[0]!='_':return'NO'c=Counter(b)flag=0ifc['_']==0:foriinrange(len(b)):ifi==0:ifb[i]==b[i+1]:continueelse:flag+=1ifi==len(b)-1:ifb[i]==b[i-1]:continueelse:flag+=1ifi>0andi<len(b)-1:ifb[i]==b[i-1]orb[i]==b[i+1]:continueelse:flag+=1form,ninc.items():ifn<=1andm!='_':return'NO'return'YES'ifnotflagelse'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 →
Python 3 Just filter for happy conditions