Skip to content

Practice String Without AAA or BBB

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

Medium#984
LeetCode Problem

String Without AAA or BBB

Problem Statement

Return any string containing exactly a copies of the letter a and b copies of the letter b, with neither aaa nor bbb appearing as a substring. The total length must be a + b.

Source: String Without AAA or BBB on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
a = 1, b = 2
Output
"abb"

# Example 2

Input
a = 4, b = 1
Output
"aabaa"

Constraints

0 <= a, b <= 100
It is guaranteed such an s exists for the given a and b.

Related LeetCode Problems

Practice more problems similar to String Without AAA or BBB.

Review your practice with PhantomCodeAI

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