Beats 39%
Intuition\n Describe your first thoughts on how to solve this problem. \nJust try using brute force approach\n\n# Approach\n Describe your approach to solving t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust try using brute force approach\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use 2 loops for iterate through the each char in string from index i to index z. Where 0<=i<n && z=n-1.\n2. for each iteration find out the direction of the move. i.e left | right | up | down. \n    To reach up we need atleast one row above the current row.\n    To reach the down we need atleast one row below the current row.\n    To reach the left we need atleast one column before the current column.\n    To reach the right we need atleast one column after the current column.\n3. If we can\'t move any side just break the loop.\n4. Now update the ans aray with the no of steps we can move for each iteration from 0 to n-1.\n5. Return the answer.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O((n(n+1))/2)$$\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        int sLen = s.length();\n        for(int i=0; i<sLen; i++){\n            int currentR = startPos[0];\n            int currentC = startPos[1];\n            int toAdd = 0;\n            for(int j=i; j<sLen; j++){\n                boolean canWeBreak = true;\n                if(s.charAt(j)==\'L\' && currentC>0){\n                    toAdd+=1;\n                    currentC-=1;canWeBreak = false; \n                }\n                else if(s.charAt(j)==\'R\' && currentC<n-1){\n                    toAdd+=1;\n                    currentC+=1;canWeBreak = false;\n                }\n                else if(s.charAt(j)==\'U\' && currentR>0){\n                    toAdd+=1;\n                    currentR-=1;canWeBreak = false;\n                }\n                else if(s.charAt(j)==\'D\' && currentR<n-1){\n                    toAdd+=1;\n                    currentR+=1;canWeBreak = false;\n                }\n                if(canWeBreak){break;}\n            }\n            ans[i]=toAdd;\n        }\n        return ans;\n    }\n}\n\n//00===>R B\n//01===>L R B\n//02===>L B\n//10===>U D R\n//11===>L R T D\n//12===>L T D\n//20===>T R\n//21===>L R T\n//22===>L T\n\n\n```
['String', 'Java']