public class BabyYoda { /* * Finds the optimal amount of eggs Baby Yoda can collect when travelling from * (c-1, r-1) (lower right) to (0, 0) (upper left). * * @param rocks If rocks[i][j] is true, then a rock (obstacle) is present there. * Otherwise false. * * @param eggs If eggs[i][j] is true, then Baby Yoda can collect one egg there. * Otherwise if there is no egg to collect, false. * * @param force Number of times that Baby Yoda can break a rock using the Force. * * @return Maximum amount of eggs that can be collected. If Baby Yoda cannot get to * the origin (too many rocks, perhaps), return -1. */ public static int maxEggs(boolean[][] rocks, boolean[][] eggs, int force) { // TODO(you!): Finish this method. return -417; } public static void main(String[] args) { // Renaming true/false so they're the same length :) final boolean F = false; final boolean T = true; // Consider writing your own test cases to debug! // [Example 1] boolean[][] rocks1 = { { F, F, F }, { F, T, T }, { F, T, F // <- baby yoda starts here }}; boolean[][] eggs1 = { { T, T, F }, { F, F, F }, { F, F, F }, }; int force1 = 1; // Baby Yoda can go up by two (breaking a rock at rocks[1][2]) // Then, go left by two to the origin (collecting eggs at eggs[0][0] and [0][1]). int expected1 = 2; System.out.println(String.format("1: Expected %d, got %d", expected1, maxEggs(rocks1, eggs1, force1))); // [Example 2] boolean[][] rocks2 = { { T, T, T }, { T, T, T }, { T, T, F }, }; boolean[][] eggs2 = { { T, T, T }, { T, T, F }, { T, T, F }, }; int force2 = 1; // Baby Yoda tragically finds himself surrounded in too many rocks, so he is unable to get to the origin. // We expect -1, despite many eggs available to be collected. int expected2 = -1; System.out.println(String.format("2: Expected %d, got %d", expected2, maxEggs(rocks2, eggs2, force2))); } }