Tilting Maze Ball
Reported by candidates from Hudson River Trading's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that wrecks a naive solution on this Hudson River Trading OA, reported October 2026, is the ball that never stops trying. A blocked move doesn't clear the direction, so the ball keeps pushing into the wall every second. The hinted pattern is BFS, but the problem is really a clean simulation with a trap or two. Endtime tops out at 100000 and the grid is at most 200 by 200, so you don't need anything fancy. If you blank on the event ordering, StealthCoder runs invisibly during the live OA and hands you the loop.
The problem
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 = 0 startCol = 0 eventTimes = [1,4,6] directions = ["R","D","L"] endTime = 8 return = [2,0] The ball follows the open outer corridor and ends in the bottom-left corner. Example 2 maze = ["...","...","..."] startRow = 1 startCol = 1 eventTimes = [2,3] directions = ["U","R"] endTime = 4 return = [0,2] The ball waits during second 1, then moves up once and right once before the boundary stops it. Example 3 maze = ["###","#.#","###"] startRow = 1 startCol = 1 eventTimes = [1] directions = ["R"] endTime = 3 return = [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 1 through endTime. The start cell is open, and every direction is U, D, L, R, or F.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there's nothing to search. The ball has one path, set by the events, so BFS is a red herring. Walk seconds 1 through endTime, keep a pointer into the sorted event list, and at each second apply the event first if its time matches, then attempt one move. Order matters: the event applies before the move on that same second. Example 2 shows it, since the ball waits at second 1 with direction F, then moves at seconds 2 and 3. Pitfalls: clearing the direction after a blocked move, treating F as a move, off-by-one on endTime 0, and checking bounds after indexing the maze instead of before. That's O(endTime) time with O(1) extra space. If the live OA has you freezing on the loop details, StealthCoder is the hedge that gives you a correct version fast.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Tilting Maze Ball cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Hudson River Trading's OA.
Hudson River Trading reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Tilting Maze Ball FAQ
Is this really a BFS problem?+
No. The hint says BFS, but the ball follows one deterministic path driven by events. There's no shortest path or branching. A direct simulation over endTime seconds is correct and fast. Reaching for BFS just adds code and bugs.
What's the main trick in Tilting Maze Ball?+
Apply the direction event first, then attempt the move, on the same second. Also keep the direction active after a blocked move. The ball doesn't reset to F when it hits a wall or the edge, it just stays put and tries again next second.
How do I handle events efficiently?+
Event times are strictly increasing, so use a single index into the arrays. At each second, if the index is in range and eventTimes[index] equals the current second, set the direction and advance the index. No map or sort is needed.
What edge cases should I test before submitting?+
Test endTime of 0, where the ball returns the start position. Test a fully walled start like Example 3. Test a ball pushing against the boundary like Example 2. Test an event at second 1 and an F event, which stops the ball.
How do I prepare for this in 48 hours?+
Practice grid simulations with direction vectors and bounds checks. Write the loop from scratch twice, with a delta map for U, D, L, R, and F as zero movement. Then run the three examples by hand. This one is about careful ordering, not an advanced algorithm.