SIMPLE WITHOUT DFS
\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        // can do with dfs by making direction grid 
```\nclass Solution {\npublic:\n    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {\n        // can do with dfs by making direction grid but lets go with an easy way\n        int d=s.size();\n        vector<int>ans(d,0);\n           int x=startPos[0];\n        int y=startPos[1];\n        for(int i=0;i<ans.size();i++)\n        {\n            ans[i]=valuekyahai(n,x,y,s,i);\n            \n        }\n        return ans;\n    }\n    int count;\n    int valuekyahai(int n,int row,int col,string s,int pos)\n    {\n        count=0;\n        for(int i=pos;i<s.size();i++)\n        {\n            if(s[i]==\'L\')\n            {\n                col--;\n            }\n            else if(s[i]==\'R\')\n            {\n                col++;\n            }\n            else if(s[i]==\'U\')\n            {\n                row--;\n            }\n            else if(s[i]==\'D\')\n            {\n                row++;\n            }\n            // lets check for the base case\n            if(row<0 || col<0 ||row>=n || col>=n)\n                break;\n            count++;\n        }\n        return count;\n    }\n};\n```
[]