Java O(n*m) Pre-compute NcR
\npublic String kthSmallestPath(int[] destination, int k) {\n        long [][]ncr = new long[31][31];\n        for(int i=0;i<=30;i++){\n            Arrays.fill(
```\npublic String kthSmallestPath(int[] destination, int k) {\n        long [][]ncr = new long[31][31];\n        for(int i=0;i<=30;i++){\n            Arrays.fill(ncr[i],1);\n        }\n        for(int i=2;i<=30;i++){\n            for(int j=0;j<=i ;j++){\n                if(j == 0){\n                    ncr[i][j] = 1;\n                }else{\n                    ncr[i][j] = (ncr[i][j-1]*(i-j+1))/(j);\n                }\n            }\n        }\n        int v = destination[0];\n        int h = destination[1];\n        StringBuilder sb = new StringBuilder("");\n        while(h > 0 && v > 0){\n            if(k <= ncr[v+h-1][v]){\n                h --;\n                sb.append("H");\n            }else{\n                sb.append("V");\n                k -= ncr[v+h-1][v];\n                v --;\n            }\n            if(h == 0){\n                while(v > 0){\n                    v--;\n                    sb.append("V");\n                }\n            }\n            if(v == 0){\n                while(h > 0){\n                    h--;\n                    sb.append("H");\n                }\n            }\n        }\n        return sb.toString();\n    }\n```
[]