Ctrl K

No Triple Letters

Easy
A caption editor rejects stretched-out words like "sooooo": no letter may appear three times in a row. Given a string text, delete as few characters as possible so that no three adjacent characters are equal, and return the result. The answer can be shown to be unique.
Example 1
text='baaaad' → 'baad'

There are four a's in a row; dropping two of them leaves "baad".

Example 2
text='xxyxxxx' → 'xxyxx'

The first pair of x's is already fine; of the four x's at the end, two remain.

Example 3
text='abab' → 'abab'

No letter repeats three times in a row, so the string stays the same.

Constraints
  • 1 ≤ len(text) ≤ 10⁵
  • text consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
text='baaaad'
Expected
'baad'

Run checks the first 3 tests in your browser. Submit checks all 37 tests on the server, hidden ones included.