Repeated-Roll Teleporter Reachability
Updated
Problem 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].
More Splunk Phone Screen questions
Similar questions at other companies
- Retryable URL MazeRamp · PHONE SCREENRamp interview questions
- Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
- Generate a Connected Graph and Find a Shortest PathThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Shortest Path Around Moving ParadesZip · PHONE SCREENZip interview questions
- Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Minimize Malware Spread by Removing a NodeVisa · OAVisa interview questions
- Minimize Malware Spread by Removing a NodeAkuna Capital · OAAkuna Capital interview questions
- Reaching Points with Perfect-Square ObstaclesIMC Trading · OAIMC Trading interview questions
- Satellite Network Message PropagationOptiver · OAOptiver interview questions