Cpp solution
\n# Code\ncpp []\nclass Solution\n{\n    public:\n        vector<int> executeInstructions(int n, vector<int> &startPos, string s)\n        {\n            vector
\n# Code\n```cpp []\nclass Solution\n{\n    public:\n        vector<int> executeInstructions(int n, vector<int> &startPos, string s)\n        {\n            vector<int> ans;\n            int x ,y, len = s.length();\n\n            for (int i = 0; i < len; i++)\n            {\n                int correctStep = 0;\n                x = startPos[0]; y = startPos[1];\n                for (int j = 0; j < s.length(); j++)\n                {\n\n                    if (s[j] == \'L\')\n                    {\n                        y--;\n                    }\n                    else if (s[j] == \'U\')\n                    {\n                        x--;\n                    }\n                    else if (s[j] == \'R\')\n                    {\n                        y++;\n                    }\n                    else\n                    {\n                        x++;\n                    }\n                    if (x < 0 || y < 0 || x >= n || y >= n)\n                        break;\n                    correctStep++;\n                }\n                ans.push_back(correctStep);\n\n                s.erase(0, 1);\n            }\n\n            return ans;\n        }\n};\n```
['C++']