|
| 1 | +<h2><a href="https://leetcode.com/problems/longest-happy-string">1304. Longest Happy String</a></h2><h3>Medium</h3><hr><p>A string <code>s</code> is called <strong>happy</strong> if it satisfies the following conditions:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>s</code> only contains the letters <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</li> |
| 5 | + <li><code>s</code> does not contain any of <code>"aaa"</code>, <code>"bbb"</code>, or <code>"ccc"</code> as a substring.</li> |
| 6 | + <li><code>s</code> contains <strong>at most</strong> <code>a</code> occurrences of the letter <code>'a'</code>.</li> |
| 7 | + <li><code>s</code> contains <strong>at most</strong> <code>b</code> occurrences of the letter <code>'b'</code>.</li> |
| 8 | + <li><code>s</code> contains <strong>at most</strong> <code>c</code> occurrences of the letter <code>'c'</code>.</li> |
| 9 | +</ul> |
| 10 | + |
| 11 | +<p>Given three integers <code>a</code>, <code>b</code>, and <code>c</code>, return <em>the <strong>longest possible happy </strong>string</em>. If there are multiple longest happy strings, return <em>any of them</em>. If there is no such string, return <em>the empty string </em><code>""</code>.</p> |
| 12 | + |
| 13 | +<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong class="example">Example 1:</strong></p> |
| 17 | + |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> a = 1, b = 1, c = 7 |
| 20 | +<strong>Output:</strong> "ccaccbcc" |
| 21 | +<strong>Explanation:</strong> "ccbccacc" would also be a correct answer. |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> a = 7, b = 1, c = 0 |
| 28 | +<strong>Output:</strong> "aabaa" |
| 29 | +<strong>Explanation:</strong> It is the only correct answer in this case. |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p> </p> |
| 33 | +<p><strong>Constraints:</strong></p> |
| 34 | + |
| 35 | +<ul> |
| 36 | + <li><code>0 <= a, b, c <= 100</code></li> |
| 37 | + <li><code>a + b + c > 0</code></li> |
| 38 | +</ul> |
0 commit comments