A warehouse floor is an R by C grid of cells. Each cell is either open (.) or an obstacle (#). A bot begins on a given open cell and follows a command string of single-step moves:
U: row - 1,D: row + 1,L: column - 1,R: column + 1.For each command the bot computes the target cell. If the target is inside the grid and open, the bot moves there; if the target is off the grid or an obstacle, the command is ignored and the bot stays put. Rows are numbered from 0 at the top; columns from 0 at the left.
Line 1: two integers R and C.
Next R lines: each a string of C characters, . or #.
Next line: two integers r0 and c0, the starting cell (guaranteed open).
Next line: a non-empty command string over U, D, L, R.
A single line r c: the bot's final row and column.
Example 1
Input
3 3 ... .#. ... 0 0 DDRR
Expected
2 2
Explanation
From (0,0): D->(1,0), D->(2,0), R->(2,1), R->(2,2). No obstacle is hit, so the bot ends at (2,2).
Example 2
Input
3 3 ... .#. ... 0 0 RD
Expected
0 1
Explanation
From (0,0): R->(0,1). Then D targets (1,1) which is an obstacle, so it is ignored and the bot stays at (0,1).
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →