We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def C(n, r):
ans = f(n) / f(r) / f(n-r)
return ans
def solve(x, y, k):
ans = ""
while k > 0:
if k < C(x+y-1, y):
ans += "H"
x -= 1
else:
ans += "V"
k -= C(x+y-1, y)
y -= 1
ans += x * "H"
ans += y * "V"
return ans
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lexicographic paths
You are viewing a single comment's thread. Return to all comments →
def C(n, r): ans = f(n) / f(r) / f(n-r) return ans
def solve(x, y, k): ans = "" while k > 0: if k < C(x+y-1, y): ans += "H" x -= 1 else: ans += "V" k -= C(x+y-1, y) y -= 1 ans += x * "H" ans += y * "V" return ans