Created
October 14, 2016 21:57
-
-
Save SahilKadam/b9d68240ef7f906b081a1ba225a6ccbc to your computer and use it in GitHub Desktop.
Given the values of and for games of Happy Ladybugs, determine if it's possible to make all the ladybugs happy. For each game, print YES on a new line if all the ladybugs can be made happy through some number of moves; otherwise, print NO to indicate that no number of moves will result in all the ladybugs being happy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import sys | |
def get_num(n, strr): | |
num = [i for i in strr if i == n] | |
return (len(num)) | |
def adjust(strr): | |
flag = True | |
lst = [] | |
for i in range(0, len(strr)): | |
if strr[i] not in lst: | |
lst.append(strr[i]) | |
else: | |
lst.remove(strr[i]) | |
if (len(lst) == 0 and get_num(strr[0], strr) != len(strr)): | |
return False | |
for j in lst: | |
if j != '_' and get_num(j, strr) == 1 : | |
flag = False | |
return flag | |
Q = int(input().strip()) | |
for a0 in range(Q): | |
n = int(input().strip()) | |
b = input().strip() | |
if adjust(b): | |
print ("YES") | |
else: | |
print ("NO") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment