Easy Implementation using DFS without any optimization
Code
# Code\n```cpp []\nclass Solution {\npublic:\n    int dr[4] = {1,0,-1,0};\n    int dc[4] = {0,1,0,-1};\n    map<char, int> dir;\n    bool valid(int r, int c, int n)\n    {\n        if (r < 0 || r >= n || c < 0 || c >= n) return false;\n        return true;\n    }\n    int solve(int r, int c, int n, string& s, int ind)\n    {\n        if (ind == s.size()) {\n            return 0;\n        }\n        int x = dir[s[ind]];\n        int ret = 0;\n        int nr = r + dr[x];\n        int nc = c + dc[x];\n                \n        if (valid(nr, nc, n)) {\n            ret = 1 + solve(nr, nc, n, s, ind + 1);\n        }\n\n        return ret;\n    }\n\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        vector<int> ret;\n        dir[\'D\'] = 0;\n        dir[\'R\'] = 1;\n        dir[\'U\'] = 2;\n        dir[\'L\'] = 3;\n        for (int i = 0, sz = s.size(); i < sz; i++) {\n            ret.push_back(solve(startPos[0], startPos[1], n, s, i));\n        }\n\n        return ret;\n    }\n};\n```
['C++']