Open ghost opened 3 years ago
import java.util.*;
public class Solution {
public static boolean canWin(int leap, int[] game) {
return isSolvable(leap, game, 0);
}
private static boolean isSolvable(int m, int[] arr, int i) {
if (i < 0 || arr[i] == 1) return false;
if ((i == arr.length - 1) || i + m > arr.length - 1) return true;
arr[i] = 1;
return isSolvable(m, arr, i + 1) || isSolvable(m, arr, i - 1) || isSolvable(m, arr, i + m);
}
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();
}
}
JAVA 8
@BinayakReddy What is it that you are trying to add?
Hey @RodneyShag, I have saved most of all my Hackerank solutions and I would love to contribute them to this repo for the C++ solutions part. So can you let me know what I should do next?