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.
def happyLadybugs(b):
# Write your code here
for colour in set(b):
if colour != "_" and b.count(colour) == 1:
return "NO"
if b.count("_") > 0:
return "YES"
for i in range(len(b)):
if i == 0 and b[0] != b[1]:
return "NO"
if i == len(b) - 1 and b[-1] != b[-2]:
return "NO"
if b[i] != b[i-1] and b[i] != b[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 →
Python Solution