#C11599. Longest Non-Consecutive Subsequence
Longest Non-Consecutive Subsequence
Longest Non-Consecutive Subsequence
Given a string s
, your task is to compute the longest subsequence such that no two consecutive characters in the subsequence are identical. In other words, for the resulting subsequence t, it must hold that for every adjacent pair ti and ti+1, t[i] ≠ t[i+1]
, and the subsequence has the maximum possible length. This problem is intended to test your ability to process strings efficiently.
Note: If the input string is empty, the output should also be an empty string.
You can use the following examples to understand the problem:
- For input
aabacbebebe
, the output isabacbebebe
. - For input
aaaa
, the output isa
. - For input
abbbbbcccccddddde
, the output isabcde
.
The solution does not involve any complex mathematical formula, but if needed, you may format any formula using LaTeX (e.g., $$t_i \neq t_{i+1}$$
).
inputFormat
The input is provided via standard input (stdin
) and consists of a single line containing the string s
.
Constraints:
- The string
s
may be empty. - The string consists only of printable characters.
outputFormat
Output the longest subsequence of the given string in which no two consecutive characters are the same. The output should be written to standard output (stdout
).
aabacbebebe
abacbebebe