[SWIFT] Using Combinatorics, beat 100%
My only proud in this awful code is that I managed to solve this problem without looking into any hints.\n\n# Code\n\nclass Solution {\n    func kthSmallestPath
My only proud in this awful code is that I managed to solve this problem without looking into any hints.\n\n# Code\n```\nclass Solution {\n    func kthSmallestPath(_ destination: [Int], _ k: Int) -> String {\n        var rows = destination[0] // V\n        var columns = destination[1] // H\n        var chars: [Character] = []\n        var leftK = k\n        while leftK >= 1, rows > 0, columns > 0 {\n            let (shifts, newK) = shifts(rows, leftK)\n            chars.append(contentsOf: Array(repeating: "H", count: columns-shifts))\n            chars.append("V")\n            rows -= 1\n            columns = shifts\n            leftK = newK\n        }\n        chars.append(contentsOf: Array(repeating: "H", count: columns))\n        chars.append(contentsOf: Array(repeating: "V", count: rows))\n        return String(chars)\n    }\n    \n    private func shifts(_ rows: Int, _ k: Int) -> (Int, Int) {\n        if k == 1 { return (0, 0) }\n        var shift = 0\n        var totalLetters = rows\n        var totalCombinations = 1\n        var prevTotalCombinations = 1\n        while k > totalCombinations {\n            prevTotalCombinations = totalCombinations\n            if totalLetters == rows {\n                totalCombinations = 1\n            } else {\n                totalCombinations *= totalLetters // had to optimize the code to pass cases with large numbers\n                totalCombinations /= (totalLetters-rows)\n            }\n            shift += 1\n            totalLetters += 1\n        }\n        return (shift-1, k - prevTotalCombinations)\n    }\n}\n\n```
['Swift', 'Combinatorics']