Java Solution (Simulation)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int[] executeInstructions(int n, int[] startPos, String s) {\n        int[] ans = new int[s.length()];\n\n        for (int i = 0; i < s.length(); ++i) {\n            int[] currPos = startPos.clone();\n\n            int letterIndex = i;\n\n            int ct = 0;\n\n            while (letterIndex < s.length()) {\n                if (s.charAt(letterIndex) == \'R\') {\n                    currPos[1]++;\n                } else if (s.charAt(letterIndex) == \'L\') {\n                    currPos[1]--;\n                } else if (s.charAt(letterIndex) == \'D\') {\n                    currPos[0]++;\n                } else if (s.charAt(letterIndex) == \'U\') {\n                    currPos[0]--;\n                }\n\n                if (currPos[0] >= n || currPos[1] >= n || currPos[0] < 0 || currPos[1] < 0) {\n                    break;\n                }\n\n                ct++;\n\n                ans[i] = ct;\n\n                letterIndex++;\n            }\n\n            System.out.println("End coordinates: " + Arrays.toString(currPos));\n        }\n\n        return ans;\n    }\n}\n```
['Java']