Algorithms & Data Structureseasy
Board Reachability with Exact Jumps
You are given board, an array of non-negative integers, and a start index. From index i you may move exactly board[i] steps left or right, staying in bounds. Return whether you can reach the last index.
board = [1, 2, 2, 2, 6, 1], start = 0 => true (0 -> 1 -> 3 -> 5) board = [3, 1, 1, 1], start = 0 => true (0 -> 3) board = [2, 0, 1, 3], start = 1 => false (board[1] = 0 traps you)
Follow-up (asked in the same round)
Minimum number of moves to reach the last index, or -1: minMovesToEnd(board, start).
board = [1, 2, 2, 2, 6, 1], start = 0 => 3
Variants to be ready for
Target is any index holding 0 (LC 1306 Jump Game III); moves are "up to" board[i] instead of exactly (LC 55/45 — greedy territory).