Tilting Maze Ball
Updated
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.
More Hudson River Trading Phone Screen questions
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Market Data Signal WatcherPHONE SCREEN · Seen Jul 2026
- Integer to String Without Built-insPHONE SCREEN · Seen May 2026
- Contact Tracing Through Timed MeetingsPHONE SCREEN · Seen Nov 2024
- Polydivisible Pandigital NumbersPHONE SCREEN · Seen Feb 2024
- Defragment a Buffer of ObjectsPHONE SCREEN · Seen Nov 2023
- Read N Bytes with read4096 Across CallsPHONE SCREEN · Seen Oct 2023
- Call Auction Clearing Price and Order FillsPHONE SCREEN · Seen Nov 2022
Similar questions at other companies
- Grid Infection with Recovery After D DaysOpenAI · PHONE SCREEN
- Days Until Poisoned Plants StabilizeApple · PHONE SCREEN
- Apply a 2048 Board MoveGlean · PHONE SCREEN
- Dense Matrix MultiplicationAmazon · PHONE SCREEN
- File-Backed Dense Game of LifeApplied Intuition · PHONE SCREEN
- Spiral Order with ObstaclesTemu · PHONE SCREEN
- Logistic Regression DiagnosticsLinkedIn · PHONE SCREEN
- Spiral Matrix TraversalByteDance · PHONE SCREEN
- S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
- Longest Consecutive Same-Color LineGoogle · PHONE SCREEN