Execution Of All Suffix Instructions Staying In A Grid(Direct Solution)
Code


# Code
```java []
class Solution {
    public int[] executeInstructions(int n, int[] st, String s) {
        int nums[]=new int[s.length()];
        for(int i=0;i<s.length();i++){
            int count=0;
            int f=st[0];
            int se=st[1];
            for(int j=i;j<s.length();j++){
                char temp=s.charAt(j);
                if(temp=='R'){
                    se++;
                    if(se==n){
                        break;
                    }
                }
                else if(temp=='L'){
                    se--;
                    if(se==-1){
                        break;
                    }
                }
                else if(temp=='U'){
                    f--;
                    if(f==-1){
                        break;
                    }
                }
                else{
                    f++;
                    if(f==n){
                        break;
                    }
                }
                count++;
            }
            nums[i]=count;
        }
        return nums;

    }
}
```
['Java']