Java - DFS
```\nclass Solution {\n    int fun(int n,int ind,int pos[],char arr[])\n    {\n        if(ind==arr.length)\n            return 0;\n        if(arr[ind]==\'R\'&&p
```\nclass Solution {\n    int fun(int n,int ind,int pos[],char arr[])\n    {\n        if(ind==arr.length)\n            return 0;\n        if(arr[ind]==\'R\'&&pos[1]+1<n)\n            return 1+fun(n,ind+1,new int[]{pos[0],pos[1]+1},arr);\n        else if(arr[ind]==\'L\'&&pos[1]-1>=0)\n            return 1+fun(n,ind+1,new int[]{pos[0],pos[1]-1},arr);\n        else if(arr[ind]==\'U\'&&pos[0]-1>=0)\n            return 1+fun(n,ind+1,new int[]{pos[0]-1,pos[1]},arr);\n        else if(arr[ind]==\'D\'&&pos[0]+1<n)\n            return 1+fun(n,ind+1,new int[]{pos[0]+1,pos[1]},arr);\n        else\n            return 0;\n    }\n    public int[] executeInstructions(int n, int[] pos, String s) {\n        \n        int i,j,len=s.length();\n        int ans[]=new int[len];\n        for(i=0;i<len;i++)\n            ans[i]=fun(n,0,pos,s.substring(i,len).toCharArray());\n        return ans;\n    }\n}\n````\n\nIf you guys get it then please upvote it:))
['Depth-First Search', 'Java']