c++ solution || easy to understand
\n\n# Code\n\nclass Solution {\npublic:\nvector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n    vector<int> ans(s.length());\n    int in
\n\n# Code\n```\nclass Solution {\npublic:\nvector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n    vector<int> ans(s.length());\n    int index = 0;\n\n    int row = startPos[0];\n    int col = startPos[1];\n\n    for(int i = 0; i < s.length(); i++) {\n        int count = 0;\n        for(int j = i; j < s.length(); j++) {\n            if(s[j] == \'L\') {\n                col -= 1;\n            } else if(s[j] == \'R\') {\n                col += 1;\n            } else if(s[j] == \'U\') {\n                row -= 1;\n            } else {\n                row += 1;\n            }\n\n            if(row >= 0 && row < n && col >=0 && col < n) {\n                count++;\n            } else {\n                break;\n            }\n        }\n            \n        row = startPos[0];\n        col = startPos[1];\n        ans[index++] = count;\n    }\n    return ans;\n    }\n};\n\n```
['Simulation', 'C++']