I just have trouble understanding the question. I am not asking for the solution. Could you please help me break down what the problem wants?
In this problem, an array represents the squares on an unusual board game.
An positive index represents an instruction to move forward (e.g. a 2 means
"move forward 2 squares"). A negative index means move backwards.
Squares that have a 0 are "end locations". Once there, no more movement is possible.
Given a board and a starting position (index), the goal of the function
is to compute the path till arriving on an end location.
You can assume:
a. An instruction will never move you off the board
b. The path will not have any cycles (we'll address this issue in the next part of the problem).- Return an ArrayList of indices visited in inputA in the order in which they were visited, starting with startLoc in position zero of the ArrayList.
- Examples:
computeBoardPathV1([2,-1,0], 1) --> <1,0,2>
computeBoardPathV1([3,3,-2,0,-2], 1) --> <1,4,2,0,3>
computeBoardPathV1([6,4,2,0,-1,-3,-5], 0) --> <0,6,1,5,2,4,3>
computeBoardPathV1([6,4,2,0,-1,-3,-5], 4) --> <4,3>
computeBoardPathV1([0], 0) --> <0>
/**
* @param input the game board
* @param startingLoc the index where the path should start
* @return The indexes traveled from startingLoc to the 0 "end location"
*/
public static ArrayList<Integer> computeBoardPathV1(int[] input, int startLoc) {
return null;
}