You are viewing a single comment's thread. Return to all comments →
Why only test case 0 is correct not any other
import java.util.*;
public class Solution {
public static boolean canWin(int leap, int[] game) { int w =0; while( w < game.length){ int setValue = 0; if ( w + leap > game.length ){ break; } else if(game[w+1]==0){ w++; } else if(game[w+1]==1){ if( w+leap< game.length && game[w+leap] == 0 ){ w+=leap; } else { return false; } } } return true; } 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(); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java 1D Array (Part 2)
You are viewing a single comment's thread. Return to all comments →
Why only test case 0 is correct not any other
import java.util.*;
public class Solution {
}