Skip to content

Practice Longest Happy String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1405
LeetCode Problem

Longest Happy String

Problem Statement

Build a string using only a, b, and c, with at most a copies of the letter a, b copies of b, and c copies of c. No three consecutive characters may be identical. Return a longest possible string satisfying these rules; if several exist, return any one. Return the empty string if no nonempty valid string exists.

Source: Longest Happy String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
a = 1, b = 1, c = 7
Output
"ccaccbcc"

# Example 2

Input
a = 7, b = 1, c = 0
Output
"aabaa"

Constraints

0 <= a, b, c <= 100
a + b + c > 0

Related LeetCode Problems

Practice more problems similar to Longest Happy String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.