Python simulation solution
Code\npython []\nclass Solution:\n    def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]:\n        directions = {\'U\': (-1, 0), \'
# Code\n```python []\nclass Solution:\n    def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]:\n        directions = {\'U\': (-1, 0), \'D\': (1, 0), \'L\': (0, -1), \'R\': (0, 1)}\n        result = []\n        for i in range(len(s)):\n            steps = 0\n            temp = startPos\n            for direction in s[i:]:\n                r, c = temp\n                dr, dc = directions[direction]\n                nr, nc = r + dr, c + dc\n                if not (0 <= nr < n and 0 <= nc < n):\n                    break\n                steps += 1\n                temp = (nr, nc)\n            result.append(steps)        \n        return result\n        \n```
['Python3']