Can anyone please explain this O(n) 6ms 100% Java code?
I found this solution from Accepted Solutions Runtime Distribution on Submission Detail page. It is a sample 6 ms submission.\n\n\n\n\n\njava\nclass Solution {\
I found this solution from **Accepted Solutions Runtime Distribution** on **Submission Detail** page. It is a sample 6 ms submission.\n\n\n![image](https://assets.leetcode.com/users/images/8b530df6-5b2e-40d2-b325-f7e4d790f0e9_1640498675.6954873.png)\n\n\n``` java\nclass Solution {\n    public int[] executeInstructions(int m, int[] startPos, String s) {\n        int [] hor = new int [2001];\n        int [] ver = new int [2001];\n        \n        Arrays.fill(hor, s.length());\n        Arrays.fill(ver, s.length());\n        \n        int h = 1000;\n        int v = 1000;\n        \n        int lB = startPos[1] + 1;\n        int rB = m - startPos[1];\n        int uB = startPos[0] + 1;\n        int dB = m - startPos[0];\n        \n        int [] result = new int [s.length()];\n        int res;\n        \n        char c;\n        \n        for (int i = s.length() - 1; i >= 0; --i){\n            c = s.charAt(i);\n            \n            if (c == \'U\')\n                ver[v++] = i; \n            else if (c == \'D\')\n                ver[v--] = i;\n            else if (c == \'R\')\n                hor[h--] = i;\n            else\n                hor[h++] = i;\n            \n            \n            res = s.length();\n            res = Math.min(res, hor[h - lB] );\n            res = Math.min(res, hor[h + rB] );\n            res = Math.min(res, ver[v - uB]);\n            res = Math.min(res, ver[v + dB]);\n            \n            result[i] = res - i;\n        }\n        \n        return result;\n    }\n}\n```
['Java']