2120. Execution of All Suffix Staying in a Grid
\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        vector<int> answer;\n        int x,y,count;\
```\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        vector<int> answer;\n        int x,y,count;\n        for(int i=0;i<s.size();i++)\n        {\n            x=startPos[1];\n            y=startPos[0];\n            count=0;\n            for(int j=i;j<s.size();j++)\n            {\n                switch(s[j])\n                {\n                    case \'L\' :\n                    {\n                        x--;\n                    }\n                    break;\n                    case \'R\' :\n                    {\n                        x++;\n                    }\n                    break;\n                    case \'U\' :\n                    {\n                        y--;\n                    }\n                    break;\n                    case \'D\' :\n                    {\n                        y++;\n                    }\n                    break;\n                }\n                if(x>=0 && x<=n-1 && y>=0 && y<=n-1)\n                {\n                    count++;\n                }\n                else\n                {\n                    break;\n                }\n            }\n            answer.push_back(count);\n        }\n        return answer;\n    }\n};\n```
['C']