FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProgramming/HackerRank/Thirty.java at patch-2 · subham500071430/JavaProgramming · GitHub
subham500071430
/
JavaProgramming
Public
forked from
karterhhgg/JavaProgramming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProgramming
/
HackerRank
/
Thirty.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (30 loc) · 1.14 KB
Breadcrumbs
JavaProgramming
/
HackerRank
/
Thirty.java
Copy path
File metadata and controls
40 lines (30 loc) · 1.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
HackerRank
;
import
java
.
util
.*;
public
class
Thirty
{
public
static
boolean
canWin
(
int
leap
,
int
[]
game
) {
// Return true if you can win the game; otherwise, return false.
return
canWinFrom
(
0
,
leap
,
game
,
new
boolean
[
game
.
length
]);
}
private
static
boolean
canWinFrom
(
int
i
,
int
leap
,
int
[]
game
,
boolean
[]
visited
) {
if
(
i
>=
game
.
length
)
return
true
;
if
(
i
<
0
||
game
[
i
] ==
1
||
visited
[
i
])
return
false
;
visited
[
i
] =
true
;
return
canWinFrom
(
i
+
leap
,
leap
,
game
,
visited
) ||
canWinFrom
(
i
+
1
,
leap
,
game
,
visited
) ||
canWinFrom
(
i
-
1
,
leap
,
game
,
visited
);
}
public
static
void
main
(
String
[]
args
) {
Scanner
scan
=
new
Scanner
(
System
.
in
);
int
q
=
scan
.
nextInt
();
while
(
q
-- >
0
) {
int
n
=
scan
.
nextInt
();
int
leap
=
scan
.
nextInt
();
int
[]
game
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++) {
game
[
i
] =
scan
.
nextInt
();
}
System
.
out
.
println
( (
canWin
(
leap
,
game
)) ?
"YES"
:
"NO"
);
}
scan
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL