Java - Recursion
\npublic int[] executeInstructions(int n, int[] startPos, String s) {\n        int [] result = new int[s.length()];\n        int sum = 0;\n        \n        for
```\npublic int[] executeInstructions(int n, int[] startPos, String s) {\n        int [] result = new int[s.length()];\n        int sum = 0;\n        \n        for (int i = 0; i < s.length(); i++) {\n            sum = executionCount(n, startPos[0], startPos[1], s.substring(i, s.length()), 0);\n            result[i] = sum;\n            sum = 0;\n        }\n        \n        return result;\n    }\n    \n    public int executionCount(int n, int i, int j, String s, int index) {\n        if (i < 0 || i > n - 1 || j < 0 || j > n - 1) return -1;\n        if (index == s.length()) return 0;\n        \n        char ch = s.charAt(index);\n        index++;\n               \n        if (ch == \'R\') j++;\n        if (ch == \'L\') j--;\n        if (ch == \'U\') i--;\n        if (ch == \'D\') i++;\n\n        return 1 + executionCount(n, i, j, s, index);\n    }\n```
[]