C++ | less than 4ms | Easy Approach
Step by step fill the string ans\n\n Count the number of permutations that exist if H is placed at index i of string ans\n If the kth permutation lies in this s
Step by step fill the string ans\n\n* Count the number of permutations that exist if H is placed at index i of string ans\n* If the kth permutation lies in this set of permutations, then place H and continue for the next i\n* Else place V and move the search window to the next set, and continue for the next i\n\n```\n#include<bits/stdc++.h>\ntypedef unsigned long long int ll;\nclass Solution {\npublic:\n    ll ncr(int n, int r)\n    {\n        ll ans = 1;\n        int r1 = max(r, n-r);\n        int r2 = n-r1;\n        \n        for(int i = 1; i<=r2; i++)\n        {\n            ans*=ll(n);\n            n--;\n            ans/=ll(i);\n        }\n        \n        return ans;\n    }\n    \n    string kthSmallestPath(vector<int>& ds, int k) {\n        ios_base::sync_with_stdio(false);\n        cin.tie(NULL);\n        string ans = "";\n        int x = ds[1];\n        int y = ds[0];\n        int n = (x+y);\n        \n        ll np = ncr(n, y);\n        \n        ll l = 1;\n        ll r = np;\n        \n        for(int i = 0; i<n; i++)\n        {\n            if(x==0)\n            {\n                ans+="V";\n                y--;\n                continue;\n            }\n            if(y==0)\n            {\n                ans+="H";\n                x--;\n                continue;\n            }\n            \n            ll nph = ncr(x-1+y, y);\n            ll nr = l+nph-ll(1);\n            if(nr >= ll(k))\n            {\n                ans+="H";\n                x--;\n            }\n            else\n            {\n                ans+="V";\n                y--;\n                l = nr+ll(1);\n            }\n            \n        }\n        \n        return ans;\n    }\n};\n```
[]