first ever hard problem 100% in time java
Intuition\n Describe your first thoughts on how to solve this problem. \ni read the hint then thought about it rlly hard. i dont think i couldve gotten it witho
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ni read the hint then thought about it rlly hard. i dont think i couldve gotten it without the hint so yeah. before hint i made the Vs into 1s and the Hs into 0s and tried to make a like numbering system where u have a fixed number of 1s and started couting up till k, it worked but it was too slow so couldnt submit, wish theyd at least tell you ur time even if time limit exceeded, btw the way you do it is you start with the smallest number for 2,3 its 00011. then start couting up, till u hit the first number with as many 1s, or u can just take the rightmost 1 then go left till ur find a zero and flip that zero and the 1 thats touching it.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwhats and approach\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nnot sre i think O(r*(c+r))\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nwhats a space lol\n# Code\n```\nclass Solution {\n    public String kthSmallestPath(int[] destination, int k) {\n\n        int nn = destination[0] + destination[1];\n        int n = nn;\n        int j = destination[0];\n        char[] res = new char[nn];\n\n        for(int p = 0; p<nn; p++) {\n            if (j == 0) {\n                res[p] = \'H\';\n                n--;\n            } else {\n                if (n == j) {\n                    res[p] = \'V\';\n                    n--;\n                    j--;\n                } else {\n                    int x = choose(n - 1, j);\n                    if (k <= x) {\n                        res[p] = \'H\';\n                        n--;\n                    } else {\n                        res[p] = \'V\';\n                        n--;\n                        j--;\n                        k = k - x;\n                    }\n                }\n            }\n        }\n        return new String(res);\n    }\n\npublic static int choose(int n, int k) {        \n        if (k == 0 || k == n) {\n            return 1;\n        }\n        int result = 1;\n        for (int i = 1; i <= k; i++) {\n            result *= n - i + 1;\n            result /= i;\n        }\n        return result;\n    }\n}\n```
['Java']