You are viewing a single comment's thread. Return to all comments →
I spent hours on this because of one dumb misstep.
Remember that you must test if x + m > n-1 or x == n-1 before you can mark a YES.
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); }
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 →
I spent hours on this because of one dumb misstep.
Remember that you must test if x + m > n-1 or x == n-1 before you can mark a YES.