Skip to content

Commit 5becd06

Browse files
COVID Pandemic and Long Queue
1 parent 174dd2d commit 5becd06

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Diff for: CodeChef/COVID-Pandemic-and-Long-Queue.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'''
2+
Due to the COVID pandemic, people have been advised to stay at least 6 feet away from any other person.
3+
Now, people are lining up in a queue at the local shop and it is your duty to check whether they are all following this advice.
4+
5+
There are a total of N spots (numbered 1 through N) where people can stand in front of the local shop.
6+
The distance between each pair of adjacent spots is 1 foot.
7+
Each spot may be either empty or occupied; you are given a sequence A1,A2,…,AN, where for each valid i, Ai=0 means that the i-th spot is empty, while Ai=1 means that there is a person standing at this spot.
8+
It is guaranteed that the queue is not completely empty.
9+
10+
For example, if N=11 and the sequence A is (0,1,0,0,0,0,0,1,0,0,1), then this is a queue in which people are not following the advice because there are two people at a distance of just 3 feet from each other.
11+
12+
You need to determine whether the people outside the local shop are following the social distancing advice or not.
13+
As long as some two people are standing at a distance smaller than 6 feet from each other, it is bad and you should report it, since social distancing is not being followed.
14+
15+
Input
16+
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
17+
The first line of each test case contains a single integer N.
18+
The next line contains N space-separated integers A1,A2,…,AN.
19+
Output
20+
For each test case, print a single line containing the string "YES" if social distancing is being followed or "NO" otherwise (without quotes).
21+
22+
Constraints
23+
1≤T≤100
24+
1≤N≤100
25+
0≤Ai≤1 for each valid i
26+
at least one spot is occupied
27+
28+
Subtasks
29+
Subtask #1 (100 points): original constraints
30+
31+
Example Input
32+
3
33+
3
34+
1 0 1
35+
7
36+
1 0 0 0 0 0 1
37+
11
38+
0 1 0 0 0 0 0 1 0 0 1
39+
Example Output
40+
NO
41+
YES
42+
NO
43+
Explanation
44+
Example case 1: The first and third spots are occupied and the distance between them is 2 feet.
45+
46+
Example case 2: The first and seventh spots are occupied and the distance between them is 6 feet.
47+
'''
48+
T = int(input())
49+
while T:
50+
N = int(input())
51+
count = 5
52+
flag = True
53+
arr = list(map(int, input().split()))
54+
for i in arr:
55+
if i and count >= 5:
56+
count = 0
57+
elif i and count < 5:
58+
flag = False
59+
break
60+
elif not i:
61+
count += 1
62+
if flag:
63+
print('YES')
64+
else:
65+
print('NO')
66+
T -= 1

0 commit comments

Comments
 (0)