JuniorString

Delete Characters to Make Fancy String

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

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

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

Example 1
Inputs = "leeetcode"
Output"leetcode"
Remove an 'e' from the first group of 'e's to create "leetcode", which has no three consecutive equal characters.
Example 2
Inputs = "aaabaaaa"
Output"aabaa"
Remove one 'a' from the first group and two 'a's from the second group to create "aabaa", which has no three consecutive equal characters.

Constraints

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

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate