You are viewing a single comment's thread. Return to all comments →
What is the issue with my iterative approach as 5 test cases are failing?
public static boolean canWin(int leap, int[] game) { int n = game.length; boolean[] visited = new boolean[n]; int i = 0; while (i < n) { if (i+1 >= n || i + leap >= n) { return true; } if (visited[i]) { return false; } visited[i] = true; if (i + leap < n && game[i + leap] == 0 && !visited[i + leap]) { i += leap; } else if (i + 1 < n && game[i + 1] == 0 && !visited[i + 1]) { i++; } else if (i - 1 >= 0 && game[i - 1] == 0 && !visited[i - 1]) { i--; } else { return false; } return false; }
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 →
What is the issue with my iterative approach as 5 test cases are failing?