Skip to main content
impol.dev

Delete Characters to Make Fancy String

Easy

A fancy text is a string where no three consecutive characters are equal.

Given a text s , delete the minimum possible number of characters from s to make it fancy .

Produce the final string after the deletion . It can be shown that the answer will always be unique .

Example 1

Input: s = "impppoldev"

Output: "imppoldev"

Explanation: Remove a 'p' from the group of three p's to create "imppoldev".

No three consecutive characters are equal, so return "imppoldev".

Example 2

Input: s = "aaabaaaa"

Output: "aabaa"

Explanation: Remove an 'a' from the first group of 'a's to create "aabaaaa".

Remove two 'a's from the second group of 'a's to create "aabaa".

No three consecutive characters are equal, so return "aabaa".

Example 3

Input: s = "aab"

Output: "aab"

Explanation: No three consecutive characters are equal, so return "aab".

Constraints

  • 1 <= s.length <= 10^5
  • s consists only of lowercase English letters.

Did this problem appear in one of your interviews?

Responses stay private.

Acceptance rate: 0%

© 2026 impol.dev. All rights reserved.PrivacyTerms