Binary Search, Easy understand solution
```\nclass Solution {\npublic:\n    \n    int bs(int st,int mid,string &s,int x,int y,int n)\n    {\n        for(int i=st;i<=mid;i++)\n        {\n            if
```\nclass Solution {\npublic:\n    \n    int bs(int st,int mid,string &s,int x,int y,int n)\n    {\n        for(int i=st;i<=mid;i++)\n        {\n            if(s[i]==\'D\')\n            {\n                x+=1;\n            }\n            else if(s[i]==\'U\')\n            {\n                x-=1;\n            }\n            else if(s[i]==\'L\')\n            {\n                y-=1;\n            }\n            else\n            {\n                y+=1;\n            }\n            \n            if(x<0 or y<0 or x>=n or y>=n)\n                return i;\n        }\n        \n        return -1;\n    }\n    \n    \n    \n    vector<int> executeInstructions(int n, vector<int>& Pos, string s) {\n        int low,mid,high,i,j,sz=s.size();\n        \n        vector<int>ans(sz,0);\n        \n        for(i=0;i<sz;i++)\n        {\n            low=i;\n            high=sz-1;\n            int anss=-1;\n            \n            while(low<=high)\n            {\n                mid=low+(high-low)/2;\n                \n                if(bs(i,mid,s,Pos[0],Pos[1],n)==-1)\n                {\n                    anss=mid;\n                    low=mid+1;\n                }\n                else\n                {\n                    high=mid-1;\n                }\n            }\n            \n            if(anss!=-1)\n                ans[i]=anss-i+1;\n        }\n        \n        \n        return ans;\n        \n    }\n};\n
['Binary Search', 'C']