A happy string is a string that:


	consists only of letters of the set ['a', 'b', 'c'].
	s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).


For example, strings "abc", "ac", "b" and "abcbabcbcb" are all happy strings and strings "aa", "baa" and "ababbc" are not happy strings.

Given two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order.

Return the kth string of this list or return an empty string if there are less than k happy strings of length n.

&nbsp;
Example 1:

Input: n = 1, k = 3
Output: "c"
Explanation: The list ["a", "b", "c"] contains all happy strings of length 1. The third string is "c".


Example 2:

Input: n = 1, k = 4
Output: ""
Explanation: There are only 3 happy strings of length 1.


Example 3:

Input: n = 3, k = 9
Output: "cab"
Explanation: There are 12 different happy string of length 3 ["aba", "abc", "aca", "acb", "bab", "bac", "bca", "bcb", "cab", "cac", "cba", "cbc"]. You will find the 9th string = "cab"


&nbsp;
Constraints:


	1 &lt;= n &lt;= 10
	1 &lt;= k &lt;= 100


class Solution:
    def getHappyString(self, n: int, k: int) -> str:
        ans = []
        letters = ['a','b','c']
        def happystr(n,prev,temp):
            if n==0:
                ans.append("".join(temp))
                return 
            for l in letters: 
                if l!=prev: 
                    happystr(n-1,l,temp+[l])
        happystr(n,"",[])
        if len(ans)<k:
            return ""
        return ans[k-1]
            
            
class Solution {

 public String getHappyString(int n, int k) {
        List<String> innerList = new ArrayList<>();
        getHappyStringUtil(n, k, new char[] { 'a', 'b', 'c' }, new StringBuilder(), innerList);
        if (innerList.size() < k)
            return "";
        return innerList.get(k - 1);
    }

    public void getHappyStringUtil(int n, int k, char[] letter, StringBuilder tempString, List<String> innerList) {
        // Base case
        if (tempString.length() == n) {
            innerList.add(tempString.toString());
            return;
        }

        // Recursive call
        for (int i = 0; i < 3; i++) {
            if (tempString.length() > 0 && tempString.charAt(tempString.length() - 1) == letter[i])
                continue;
            tempString.append(letter[i]);
            getHappyStringUtil(n, k, letter, tempString, innerList);
            tempString.deleteCharAt(tempString.length() - 1);
        }

    }
}
class Solution {
    private:
    void happy(string s, vector<char> &v, int n, vector<string> &ans){
        if(s.size() == n){
            ans.push_back(s);
            return;
        }
        for(int i=0; i<3; i++){
            if(s.back() != v[i]){
                s.push_back(v[i]);
                happy(s,v,n,ans);
                s.pop_back();
            }
        }
    }
public:
    string getHappyString(int n, int k) {
        vector<char> v = {'a', 'b', 'c'};
        vector<string> ans;
        string s = "";
        happy(s,v,n,ans);
        if(ans.size() < k){
            return "";
        }
        else{
            return ans[k-1];
        }
    }
};
var getHappyString = function(n, k) {
    const arr = ['a','b','c'], finalArr = ['a','b','c'];
    let chr = '', str = '';
    if(finalArr[finalArr.length-1].length === n && finalArr[0].length === n ) {
        return finalArr[k-1] && finalArr[k-1].length === n ? finalArr[k-1] : '';
    }
    for(; finalArr.length < k || finalArr[0].length <= n;) {
        str = finalArr.shift();
        for(let index2 = 0; index2 < 3; index2++){
            chr = str[str.length-1];
            if(chr !== arr[index2]) {
                finalArr.push(str+arr[index2]);
            }
        }
        if(finalArr[finalArr.length-1].length === n && finalArr[0].length === n ) break;
    }
    return finalArr[k-1] ? finalArr[k-1] : '';
};
The k-th Lexicographical String of All Happy Strings of Length n