Medium
Quiz
#1405 Longest Happy String
APPROACH
A string s is happy if it satisfies all of the following:
- s only contains the letters 'a', 'b', and 'c'.
- s does not contain "aaa", "bbb", or "ccc" as a substring.
- s contains at most a occurrences of 'a'.
- s contains at most b occurrences of 'b'.
- s contains at most c occurrences of 'c'.
Given three integers a, b, and c, construct and return the longest possible happy string. Return any valid answer, or "" if none exists.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: a = 1, b = 1, c = 7
Output: "ccaccbcc"
Explanation: "ccbccacc" would also be a correct answer.
Example 2:
Input: a = 7, b = 1, c = 0
Output: "aabaa"
Explanation: It is the only correct answer in this case.
1 of 4
1:00
What is the optimal approach for this problem?