✅JAVA SOLUTION | EASY
\n\n# Code\n\nclass Solution {\n    public int[] executeInstructions(int n, int[] startPos, String s) {\n        int[] arr = new int[s.length()];\n        for(i
\n\n# Code\n```\nclass Solution {\n    public int[] executeInstructions(int n, int[] startPos, String s) {\n        int[] arr = new int[s.length()];\n        for(int i=0;i<s.length();i++){\n            arr[i] = execution(s.substring(i),n,startPos);\n        }\n        return arr;\n    }\n    \n    private int execution(String str,int n,int[] arr){\n        int move = 0;\n         int row = arr[0];\n         int col = arr[1];\n        for(int i=0;i<str.length();i++){\n            if(str.charAt(i)==\'R\'){\n                if(col < n-1){\n                     move++;\n                     col++;\n                }\n                else return move;\n            }\n\n            else if(str.charAt(i)==\'D\'){\n                if(row < n-1){\n                     move++;\n                     row++;\n                }\n                else return move;\n            }\n\n            else if(str.charAt(i)==\'L\'){\n                if(col > 0){\n                     move++;\n                     col--;\n                }\n                else return move;\n            }\n\n            else if(str.charAt(i)==\'U\'){\n                if(row > 0){\n                     move++;\n                     row--;\n                }\n                else return move;\n            }\n        }\n        return move;\n    }\n}\n```
['Java']