Robot floor traversal

Write codeEasy15 min

Your task

An overnight cleaning robot works a terminal floor plan given as a rectangular grid of single character cells, where '.' is open floor and '#' is a fixed obstacle such as a kiosk or a gate desk. The robot starts on the open cell at start_row and start_col, then reads the instruction string one character at a time. 'N' moves it one row up, 'S' one row down, 'E' one column right, and 'W' one column left. An instruction that would carry it off the plan or onto an obstacle is refused: the robot stays where it is and goes on to the next instruction. Return the cell it finishes on as [row, column]. An empty instruction string leaves it on its starting cell.

Examples

final_stop_cell(plan: list[list[str]], start_row: int, start_col: int, moves: str) -> list[int]
Example 1
Inputfinal_stop_cell([[".", ".", "."], [".", "#", "."], [".", ".", "."]], 0, 0, "SSEE")
Output[2, 2]
Example 2
Inputfinal_stop_cell([[".", ".", "."], [".", "#", "."], [".", ".", "."]], 0, 0, "SE")
Output[1, 0]
Example 3
Inputfinal_stop_cell([[".", ".", "."], [".", "#", "."], [".", ".", "."]], 0, 0, "NNNNWWWW")
Output[0, 0]