Python solution quite clean
\nclass Solution:\n    def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]:\n        x = startPos[0]\n        y = startPos[1]\n     
```\nclass Solution:\n    def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]:\n        x = startPos[0]\n        y = startPos[1]\n        result = []\n        def factory(order,x,y):\n            if order == "R":\n                x,y = right(x,y)\n            elif order == "L":\n                x,y = left(x,y)\n            elif order == "U":\n                x,y = up(x,y)\n            elif order == "D":\n                x,y = down(x,y)\n            else:\n                print("something is wrong")\n            return x,y\n        #if x >= n or y >= n or x < 0 or y<0 -> stop\n        def checker(x,y,n):\n            if x >= n or y >= n or x<0 or y<0:\n                return False\n            else:\n                return True\n            \n        def right(x,y):\n            x += 1\n            return x,y \n        def left(x,y):\n            x -= 1\n            return x,y\n        def up(x,y):\n            y -= 1\n            return x,y\n        def down(x,y):\n            y += 1\n            return x,y\n        for i in range(0,len(s)):\n            x = startPos[1]\n            y = startPos[0]\n            count = 0\n            for order in s[i:]:\n                x,y = factory(order,x,y)\n                if checker(x,y,n):\n                    count += 1\n                else:\n                    \n                    break\n            result.append(count)\n        return result\n```
['Python']