The k-th Lexicographical String of All Happy Strings of Length n
https://leetcode.com/contest/biweekly-contest-24/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/
class Solution:
def getHappyString(self, n: int, k: int) -> str:
def generate(prev):
if len(prev) == n:
yield prev
return
for ch in "abc":
if not prev or prev[-1] != ch:
for s in generate(prev+ch):
yield s
for i,val in enumerate(generate(""),1):
if i == k:
return val
return ""Previous1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is KNext17. Letter Combinations of a Phone Number
Last updated