[Java] Iterative Math solution in O((N + M)²)
While we haven\'t reached the destination we need to do the following:\nIf moving right we will have enough number of combinations (k <= number of combinations)
While we haven\'t reached the destination we need to do the following:\nIf moving right we will have enough number of combinations (`k <= number of combinations`), then we can go right, else go down\n\n```\nclass Solution {\n    public String kthSmallestPath(int[] destination, int k) {\n        int y = destination[0], x = destination[1];\n        StringBuilder answer = new StringBuilder();\n        \n        while (x != 0 && y != 0) {\n            int move = combinations(x + y - 1, y);\n            \n            if (k <= move) {\n                answer.append(\'H\');\n                x--;\n            } else {\n                answer.append(\'V\');\n                k -= move;\n                y--;\n            }\n        }\n        \n        while (x != 0) {\n            answer.append(\'H\');\n            x--;\n        }\n        \n        while (y != 0) {\n            answer.append(\'V\');\n            y--;\n        }\n        \n        return answer.toString();\n    }\n    \n    private int combinations(int a, int b) {\n        long top = 1;\n        long bottom = 1;\n        \n        for (int i = b + 1; i <= a; i++) {\n            top *= i;\n        }\n        \n        for (int i = 1; i <= a - b; i++) {\n            bottom *= i;\n        }\n        \n        return (int) (top / bottom);\n    }\n}\n```
[]