Sun. Jul 3rd, 2022

# COVID Pandemic and Long Queue Codechef Solution

#### Bydivya katoch

Nov 7, 2021

Due to the COVID pandemic, people have been advised to stay at least 66 feet away from any other person. 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.

There are a total of N spots (numbered 11 through NN) where people can stand in front of the local shop. The distance between each pair of adjacent spots is 1 foot. 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. It is guaranteed that the queue is not completely empty.

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.

You need to determine whether the people outside the local shop are following the social distancing advice or not. 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.

### Input

• The first line of the input contains a single integer T denoting the number of test cases. The description of TT test cases follows.
• The first line of each test case contains a single integer N.
• The next line contains NN space-separated integers A1,A2,…,AN.

### Output

For each test case, print a single line containing the string `"YES"` if social distancing is being followed or `"NO"` otherwise (without quotes).

### Constraints

• 1≤T≤1001≤T≤100
• 1≤N≤1001≤N≤100
• 0≤Ai≤10≤Ai≤1 for each valid ii
• at least one spot is occupied

### Subtasks

Subtask #1 (100 points): original constraints

### Sample Input 1

```3
3
1 0 1
7
1 0 0 0 0 0 1
11
0 1 0 0 0 0 0 1 0 0 1
```

```NO
YES
NO
```

### Explanation

Example case 1: The first and third spots are occupied and the distance between them is 22 feet.

Example case 2: The first and seventh spots are occupied and the distance between them is 66 feet.

## COVID Pandemic and Long Queue – CodeChef Solution in JAVA

```import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
try {
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int[] a =new int[n];
boolean count=true;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n-1;i++)
{
if(a[i]==1)
{
for(int j=i+1;j<n;j++)
{
if(a[j]==1 && j-i<6)
{
count=false;
break;
}
}
}
}
if(count)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
} catch(Exception e) {
}
}
}
```

## COVID Pandemic and Long Queue- CodeChef Solution in CPP

```#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n,ele,j=0,flag=1;cin>>n;
int arr[n];
for(int i=0;i<n;i++) {
cin >> ele;
if(ele==1)arr[j++]=i;
}
for(int i=j-1;i>=1;i--){
if(arr[i]-arr[i-1]<6){flag=0;break;}
}
cout<<(flag?"YES\n":"NO\n");
}
return 0;
}
```

## COVID Pandemic and Long Queue-CodeChef Solution in Python

```for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
i,flag,c=0,0,0
while(i<n):
if l[i]==1:
i+=1
c=0
#print(i)
while(i<n and c!=5):
if l[i]==0:
c+=1
else:
flag=1
break
i+=1
else:
i+=1
if flag==1:
print("NO")
break
if flag==0:
print("YES")

```

Disclaimer: The above Problem (COVID Pandemic and Long Queue ) is generated by CodeChef but the solution is provided by Codeworld19.This tutorial is only for Educational and Learning purpose.