|
| 1 | +<p>A <strong>happy string</strong> is a string that:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>consists only of letters of the set <code>['a', 'b', 'c']</code>.</li> |
| 5 | + <li><code>s[i] != s[i + 1]</code> for all values of <code>i</code> from <code>1</code> to <code>s.length - 1</code> (string is 1-indexed).</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>For example, strings <strong>"abc", "ac", "b"</strong> and <strong>"abcbabcbcb"</strong> are all happy strings and strings <strong>"aa", "baa"</strong> and <strong>"ababbc"</strong> are not happy strings.</p> |
| 9 | + |
| 10 | +<p>Given two integers <code>n</code> and <code>k</code>, consider a list of all happy strings of length <code>n</code> sorted in lexicographical order.</p> |
| 11 | + |
| 12 | +<p>Return <em>the kth string</em> of this list or return an <strong>empty string</strong> if there are less than <code>k</code> happy strings of length <code>n</code>.</p> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong class="example">Example 1:</strong></p> |
| 16 | + |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> n = 1, k = 3 |
| 19 | +<strong>Output:</strong> "c" |
| 20 | +<strong>Explanation:</strong> The list ["a", "b", "c"] contains all happy strings of length 1. The third string is "c". |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> n = 1, k = 4 |
| 27 | +<strong>Output:</strong> "" |
| 28 | +<strong>Explanation:</strong> There are only 3 happy strings of length 1. |
| 29 | +</pre> |
| 30 | + |
| 31 | +<p><strong class="example">Example 3:</strong></p> |
| 32 | + |
| 33 | +<pre> |
| 34 | +<strong>Input:</strong> n = 3, k = 9 |
| 35 | +<strong>Output:</strong> "cab" |
| 36 | +<strong>Explanation:</strong> 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 9<sup>th</sup> string = "cab" |
| 37 | +</pre> |
| 38 | + |
| 39 | +<p> </p> |
| 40 | +<p><strong>Constraints:</strong></p> |
| 41 | + |
| 42 | +<ul> |
| 43 | + <li><code>1 <= n <= 10</code></li> |
| 44 | + <li><code>1 <= k <= 100</code></li> |
| 45 | +</ul> |
0 commit comments