-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArray1DPart2.java
More file actions
66 lines (66 loc) · 905 Bytes
/
Array1DPart2.java
File metadata and controls
66 lines (66 loc) · 905 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.*;
import java.util.Scanner;
class Array1DPart2
{
public static void main(String[]args)
{
Scanner venki=new Scanner(System.in);
int q=venki.nextInt();
int i,x=0,flag=0;
for(int t=0;t<q;t++)
{
int n=venki.nextInt();
int a[]=new int[n];
int leap=venki.nextInt();
for(i=0;i<n;i++)
{
a[i]=venki.nextInt();
}
i=0;x=0;flag=0;
for(int j=0;j<n;j++)
{
try
{
x=i-1;
if(a[i+leap]==0)
{
i=i+leap;
continue;
}
else if(x>0)
{
if(a[i-1]==0)
{
i=i-1;
continue;
}
}
else if(a[i+1]==0)
{
i=i+1;
continue;
}
else
{
flag=2;
break;
}
x=i;
}
catch(Exception e)
{
flag=1;
break;
}
}
if(flag==1)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}