You are viewing a single comment's thread. Return to all comments →
Python3; After realizing 1 empty field gives you possibility to place any existing color anywhere
from collections import Counter def are_happy(b): for i in range(len(b)): happy = False if i > 0: if b[i-1] == b[i]: happy = True if i < len(b) - 1: if b[i+1] == b[i]: happy = True if not happy: return False return True def happyLadybugs(b): c = Counter(b) if c['_'] < 1: if are_happy(b): return 'YES' else: return 'NO' for key, count in c.most_common()[::-1]: if count == 1 and key != '_': return 'NO' if count > 1: return 'YES' return 'YES'
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
Python3; After realizing 1 empty field gives you possibility to place any existing color anywhere