c++ solution
\nclass Solution {\npublic:\n    vector<pair<int,int>>dir={{-1,0},{1,0},{0,1},{0,-1}};\n    int find(string s,int n,int x,int y)\n    {\n        auto is_safe=[&
```\nclass Solution {\npublic:\n    vector<pair<int,int>>dir={{-1,0},{1,0},{0,1},{0,-1}};\n    int find(string s,int n,int x,int y)\n    {\n        auto is_safe=[&](int nx,int ny)\n        {\n            if(nx>=0&&ny>=0&&nx<n&&ny<n)\n            {\n                return true;\n            }\n            return false;\n        };\n        int count=0;\n        int nx=x;\n        int ny=y;\n        for(int i=0;i<s.size();i++)\n        {\n            if(s[i]==\'L\')\n            {\n                nx+=dir[3].first;\n                ny+=dir[3].second;\n            }\n            else if(s[i]==\'R\')\n            {\n                 nx+=dir[2].first;\n                ny+=dir[2].second;\n            }\n            else if(s[i]==\'U\')\n            {\n                 nx+=dir[0].first;\n                ny+=dir[0].second;\n            }\n            else if(s[i]==\'D\')\n            {\n                 nx+=dir[1].first;\n                ny+=dir[1].second;\n            }\n            // cout<<nx<<"  "<<ny<<"    ";\n              if(is_safe(nx,ny))\n                {\n                    count++;\n                }\n                else\n                {\n                    return count;\n                }\n           \n        }\n        return count;\n    }\n    vector<int> executeInstructions(int n, vector<int>& nums, string s) \n    {\n        vector<int>ans(s.size(),0);\n        for(int i=0;i<s.size();i++)\n        {\n            int count=find(s.substr(i),n,nums[0],nums[1]);\n                ans[i]=count;\n            // cout<<"new"<<endl;\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'C', 'C++']