Problem · Graph
Repeated-Roll Teleporter Reachability
Learn this problemProblem statement
A board contains integer squares from 1 through end. Starting at start, you may roll a die with faces 1 through sides any number of times.
After each roll, discard a move whose initial landing exceeds end. Otherwise, if the landing square is a teleporter source, move once to its destination without chaining. Return whether square end is reachable. A player already on end has reached it.
Function
canReachEnd(start: int, end: int, sides: int, teleporters: int[][]) → booleanExamples
Example 1
start = 1end = 8sides = 2teleporters = [[2,6]]return = trueRoll 1 to reach 2, teleport to 6, then roll 2 to reach 8.
Example 2
start = 1end = 6sides = 1teleporters = [[2,1]]return = falseEvery roll lands on 2 and returns to 1, so 6 is unreachable.
Constraints
1 <= start <= end <= 10^5.1 <= sides <= 100.- Teleporter sources are unique, and every endpoint is in
[1, end].