Easy/Effecient Approach|82%Beats in Time|
Intuition\nTraverse across and find the limits\n\n# Approach\nFor each iteration consider each start of instruction\nCheck the boundaries\nCheck for all the ins
# Intuition\nTraverse across and find the limits\n\n# Approach\nFor each iteration consider each start of instruction\nCheck the boundaries\nCheck for all the instructions\nBreak if overboundry/complete all the instructions\nAdd the result to vector and return\n\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        vector<int> res;\n        int row = startPos[0];\n        int col = startPos[1];\n        int count = 0;\n        for(int i = 0; i < s.size(); i++)\n        {\n            count = 0;\n            row = startPos[0];\n            col = startPos[1];\n            for(int j = i; j < s.size(); j++)\n                if(s[j] == \'R\')\n                    if(col < n - 1){\n                        count++;\n                        col++;\n                    }\n                    else                        break;\n                else if(s[j] == \'L\')\n                    if(col > 0){                        \n                        count++;\n                        col--;\n                    }\n                    else                        break;\n                else if(s[j] == \'D\')\n                    if(row < n - 1){                        \n                        count++;\n                        row++;\n                    }\n                    else                        break;\n                else\n                    if(row > 0){                        \n                        count++;\n                        row--;\n                    }\n                    else                        break;\n            res.push_back(count);\n        }\n        return res;\n    }\n};\n```
['C++']