FastPrepOne-Roll Teleporter Landings

One-Roll Teleporter Landings

Splunk logoSplunk● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

A board contains integer squares from 1 through end. You begin at start and roll a die with faces 1 through sides exactly once.

If the rolled landing square is the source of a teleporter, move once to its destination. Do not activate another teleporter during the same roll. Discard rolls whose initial landing square is greater than end. Return all distinct final positions in increasing order.

Function

oneRollLandings(start: int, end: int, sides: int, teleporters: int[][]) → int[]

Examples

Example 1

start = 2end = 10sides = 4teleporters = [[3,9],[5,1]]return = [1,4,6,9]

The four initial landings are 3, 4, 5, and 6. Teleporters change 3 to 9 and 5 to 1.

Example 2

start = 8end = 10sides = 4teleporters = [[9,10],[10,10]]return = [10]

Only initial landings 9 and 10 remain on the board, and both finish at 10.

Constraints

  • 1 <= start <= end <= 10^5.
  • 1 <= sides <= 10^5.
  • Teleporter sources are unique, and every endpoint is in [1, end].

More Splunk problems

See Splunk hiring insights
public int[] oneRollLandings(int start, int end, int sides, int[][] teleporters) {
    // Return sorted distinct landing positions.
}
start2
end10
sides4
teleporters[[3,9],[5,1]]
expected[1,4,6,9]
Checking account…