We’re preparing your current view and syncing the latest data.
K-th Happy String
gfgA happy string is a string that has no two consecutive characters that are the same, and is composed only of the letters 'a', 'b', and 'c'. Given two integers n and k, return the k-th lexicographical happy string of length n. If there are fewer than k happy strings of length n, return an empty string.
Two integers n and k where 1 <= n <= 10 and 1 <= k <= 1000.
A string representing the k-th lexicographical happy string of length n, or an empty string if it does not exist.
1 <= n <= 10; 1 <= k <= 1000
Example 1
Input
n = 1, k = 3
Output
"c"
Explanation
"a", "b", "c" are all happy strings of length 1. The 3rd lexicographical is "c".
Example 2
Input
n = 1, k = 4
Output
""
Explanation
There are only 3 happy strings of length 1, so the 4th does not exist.
Example 3
Input
n = 3, k = 9
Output
"cab"
Explanation
There are 12 happy strings of length 3, the 9th lexicographically is "cab".