Java || straightforward solution...
Complexity
Time complexity: O(n^2) => where n is the length of s;

Space complexity: O(n) => where n is the length of s;
Code
# Complexity
- Time complexity: O(n^2) => where n is the length of s;
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n) => where n is the length of s;
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int[] executeInstructions(int n, int[] startPos, String s) {
        int[] arr = new int[s.length()];
       

        for(int i = 0; i < s.length(); i++){
            
            int topLimit = 0;
            int bottomLimit = n-1;
            int rightLimit = n-1;
            int leftLimit = 0;
            String str = s.substring(i,s.length());
            int k = 0; 
            int posX = startPos[0];
            int posY = startPos[1];
            for(int j = 0; j < str.length(); j++){               

                if(str.charAt(j) == 'R'){
                    if(posY < rightLimit){
                        k++;
                        posY++;
                    }else{
                        break;
                    }
                }else if(str.charAt(j) == 'D'){
                    if(posX < bottomLimit){
                        k++;
                        posX++;
                    }else{
                        break;
                    }
                }else if(str.charAt(j) == 'U'){
                    if(posX > topLimit){
                        k++;
                        posX--;
                    }else{
                        break;
                    }
                }else if(str.charAt(j) == 'L'){
                    if(posY > leftLimit){
                        k++;
                        posY--;
                    }else{
                        break;
                    }
                }


            }
            
            arr[i] = k;
            
        }
        return arr;
    }
}
```
['Java']