Easy c++ solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n    void CountMoves(pair<int, int> a, string s, vector<int>& moves, int n) {\n        pair<int, int> b = a;\n        int count = 0;\n\n        for (int i = 0; i < s.size(); i++) {\n            if (s[i] == \'R\') {\n\n                if (b.second == n)\n                    break;\n                int x = b.second + 1;\n                if (x < n) {\n                    b.second++;\n                    count++;\n                } else\n                    break;\n            }\n\n            if (s[i] == \'L\') {\n                if (b.second == 0)\n                    break;\n                int x = b.second - 1;\n                if (x < n) {\n                    b.second--;\n                    count++;\n                } else\n                    break;\n            }\n\n            if (s[i] == \'D\') {\n                if (b.second == n)\n                    break;\n                int x1 = b.first + 1;\n                if (x1 < n) {\n                    b.first++;\n                    count++;\n\n                }\n\n                else\n                    break;\n            }\n\n            if (s[i] == \'U\') {\n                if (b.first == 0)\n                    break;\n                int x1 = b.first - 1;\n                if (x1 < n) {\n                    b.first--;\n                    count++;\n\n                }\n\n                else\n                    break;\n            }\n        }\n\n        moves.push_back(count);\n    }\n\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n\n        pair<int, int> a = {startPos[0], startPos[1]};\n\n        vector<int> moves;\n\n        while (!s.empty()) {\n            CountMoves(a, s, moves, n);\n            reverse(s.begin(), s.end());\n\n            s.erase(s.size() - 1);\n            reverse(s.begin(), s.end());\n        }\n\n        return moves;\n    }\n};\n```
['C++']