Just Follow The Path
\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        int m = s.length(), moves, j, x, y;\n       
```\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        int m = s.length(), moves, j, x, y;\n        vector<int> res(m, 0);\n        for (int i = 0; i < m; i++) {\n            x = startPos[0], y = startPos[1], j = i, moves = 0;\n            while (j < m) {\n                if (s[j] == \'L\') y--;\n                else if (s[j] == \'R\') y++;\n                else if (s[j] == \'U\') x--;\n                else if (s[j] == \'D\') x++;\n                if (!inbounds(x, y, n)) break;\n                moves++, j++;\n            }\n            res[i] = moves;\n        }\n        return res;\n    }\n    \nprivate:\n    bool inbounds(int &x, int &y, int &n) {\n        return x >= 0 && x < n && y >= 0 && y < n;\n    }\n};\n```
[]