The k-th Lexicographical String of All Happy Strings of Length n

Medium · Backtracking · about 15 minutes

Asked at Google, Amazon, Microsoft.

A happy string uses only 'a', 'b', 'c' and has no two equal adjacent characters. Return the k-th happy string of length n in lexicographic order, or "" if there are fewer than k.

Related guides