forked from jayaprakash9603/MountBlue-Job-Challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHappyLadybugs.py
More file actions
36 lines (26 loc) · 706 Bytes
/
HappyLadybugs.py
File metadata and controls
36 lines (26 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'happyLadybugs' function below.
#
# The function is expected to return a STRING.
# The function accepts STRING b as parameter.
#
def happyLadybugs(b):
if any(b.count(bug)==1 for bug in b if bug != '_') or ('_' not in b and any(b[i]!=b[i+1] and b[i]!=b[i-1] for i in range(1, n-2))):
return 'NO'
else:
return 'YES'
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
g = int(input().strip())
for g_itr in range(g):
n = int(input().strip())
b = input()
result = happyLadybugs(b)
fptr.write(result + '\n')
fptr.close()