Delete Characters to Make Fancy String

A fancy string is a string in which no three consecutive characters are equal. Given a string `s`, delete the minimum possible number of characters from `s` to make it fancy, and return the final string. The answer is always unique.

30:00

Delete Characters to Make Fancy String
easy
Free written solution
Topics
Companies

A fancy string is a string in which no three consecutive characters are equal. Given a string s, delete the minimum possible number of characters from s to make it fancy, and return the final string. The answer is always unique.

Example 1:
Input: {"s":"leeetcode"}
Output: leetcode
Constraints:
  • 1 <= s.length <= 10^5

  • s consists only of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"leeetcode"}

Start with an empty output. A character may join it unless the last two output characters are already that same letter.

s

read 0/9 · deleted 0

0

l

 

e

 

e

 

e

 

t

5

c

 

o

 

d

 

e

the check: last two of out vs. incoming

Waiting for the first character.

out (0 chars, number = position in its run)

Variables
VariableValue
len(s)9
out""
DepthFunction Call
Stack empty
0/11