|| USING DFS || EASY TO IMPLEMENT || 
PLEASE UPVOTE IF YOU LIKE THE APPROACH !!Code
**PLEASE UPVOTE IF YOU LIKE THE APPROACH !!**

# Code
```cpp []
class Solution {
public:
   int dfs(int i,int x,int y,string s,int n){
    if(i==s.length() or x>=n or y>=n or x<0 or y<0){
        return 0;
    }
    if(s[i]=='R' and y+1<n){
        return 1+dfs(i+1,x,y+1,s,n);
    }
    else if(s[i]=='D' and x+1<n){
        return 1+dfs(i+1,x+1,y,s,n);
    }
    else if(s[i]=='L' and y-1>=0){
        return 1+dfs(i+1,x,y-1,s,n);
    }
    else if(s[i]=='U' and x-1>=0){
        return 1+dfs(i+1,x-1,y,s,n);
    }
    return 0;
   }
    vector<int> executeInstructions(int n, vector<int>& startPos, string s) {
        int x=s.length();

        vector<int>ans(x,0);
        for(int i=0;i<x;i++){
            ans[i]=dfs(i,startPos[0],startPos[1],s,n);
        }
        return ans;
    }
};
```
['C++']