1643. Kth Smallest Instructions
On This Page
class Solution:
def kthSmallestPath(self, destination: List[int], k: int) -> str:
v, h = destination
res = []
for _ in range(h + v):
if h == 0:
res.append("V")
else:
x = comb(h + v - 1, h - 1)
if k > x:
res.append("V")
v -= 1
k -= x
else:
res.append("H")
h -= 1
return "".join(res)