#C2868. Make Alternating String
Make Alternating String
Make Alternating String
You are given a string s
consisting of only the characters 'a'
and 'b'
. Your task is to remove the minimum number of characters from s
so that the resulting string is alternating, meaning no two adjacent characters are the same.
An alternating string is defined as a string where every pair of consecutive characters are different. For example, both "abab"
and "baba"
are alternating strings, whereas "aab"
is not.
Note: It is guaranteed that the input string contains only the characters "a"
and "b"
.
Mathematical Expression: The problem can be formalized as follows. Given a string \( s = s_1s_2\dots s_n \) where \( s_i \in \{a, b\} \), find a subsequence \( s' \) of \( s \) such that \( s' \) is alternating and \( |s| - |s'| \) is minimized.
inputFormat
The input is read from standard input. It consists of a single line that contains the string s
which only includes lowercase characters a
and b
. The string may be empty.
outputFormat
Print the resulting alternating string to standard output.
## sampleaab
ab
</p>