C# Combinatorial Optimization with Greedy Algorithms Solution
Intuition\n Describe your first thoughts on how to solve this problem. To solve the problem of finding the kth lexicographically smallest path that leads Bob to
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->To solve the problem of finding the kth lexicographically smallest path that leads Bob to the destination (row, column) using the instructions "H" (right) and "V" (down), we can take a combinatorial approach.\n___\n\n# Approach\n<!-- Describe your approach to solving the problem. -->//  Combination Method: The \'Combination(int n, int r)\' function calculates the number of combinations\n//  \'C(n, r)\', which is the number of ways to choose \'r\' items from \'n\' items.\n//  Path Construction:\n//  *For each step in the total number of moves:\n//  **Decide whether to move right ("H") or down ("V") by checking the possible number of paths if "H" is \n//  chosen.\n//  *If the kth path lies within the range of paths starting with "H", choose "H".\n//  *Otherwise, choose "V" and adjust \'k\' accordingly.\n___\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(row + column).\n___\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(1) (ignoring the space required for the output string).\n___\n\n# Code\n```csharp []\npublic class Solution {\n    public string KthSmallestPath(int[] destination, int k) {\n        int row = destination[0];\n        int col = destination[1];\n        int totalMoves = row + col;\n        \n        var path = new StringBuilder();\n        \n        for (int i = 0; i < totalMoves; i++) {\n            if (col > 0) {\n                int chooseH = Combination(row + col - 1, col - 1);\n                \n                if (k <= chooseH) {\n                    path.Append(\'H\');\n                    col--;\n                } else {\n                    path.Append(\'V\');\n                    k -= chooseH;\n                    row--;\n                }\n            } else {\n                path.Append(\'V\');\n                row--;\n            }\n        }\n        \n        return path.ToString();\n    }\n\n    // Method to calculate combination nCr = n! / (r! * (n-r)!)\n    private int Combination(int n, int r) {\n        if (r > n) return 0;\n        long result = 1;\n        for (int i = 1; i <= r; i++) {\n            result = result * (n - i + 1) / i;\n        }\n        return (int)result;\n    }\n}\n```
['Array', 'Math', 'Greedy', 'Combinatorics', 'C#']