Tilting Maze Ball
Problem statement
A ball sits on an open cell . in a rectangular maze whose walls are #. The ball initially has direction F and does not move.
For each integer second from 1 through endTime, first apply a direction event at that second if one exists, then attempt to move the ball one cell in the current direction. Directions are U, D, L, R, and F. A move that would leave the maze or enter a wall is ignored; the direction remains active.
Return the ball's final zero-based [row, column].
Function
finalMazePosition(maze: String[], startRow: int, startCol: int, eventTimes: int[], directions: String[], endTime: int) → int[]Examples
Example 1
maze = ["....",".##.","...."]startRow = 0startCol = 0eventTimes = [1,4,6]directions = ["R","D","L"]endTime = 8return = [2,0]The ball follows the open outer corridor and ends in the bottom-left corner.
Example 2
maze = ["...","...","..."]startRow = 1startCol = 1eventTimes = [2,3]directions = ["U","R"]endTime = 4return = [0,2]The ball waits during second 1, then moves up once and right once before the boundary stops it.
Example 3
maze = ["###","#.#","###"]startRow = 1startCol = 1eventTimes = [1]directions = ["R"]endTime = 3return = [1,1]Walls block every attempted move.
Constraints
1 <= maze.length, maze[0].length <= 200.0 <= endTime <= 100000.0 <= eventTimes.length = directions.length <= endTime.- Event times are strictly increasing and each lies from
1throughendTime. - The start cell is open, and every direction is
U,D,L,R, orF.