#C9331. Maximum Consecutive Matching Pairs
Maximum Consecutive Matching Pairs
Maximum Consecutive Matching Pairs
Given a string s
, find the maximum length of a consecutive substring where every adjacent pair of characters consists of the same character. In other words, you need to find the longest contiguous segment in s
that can be divided into pairs (each pair having two identical characters).
Example:
- For
s = "aabbcc"
, the entire string can be paired as "aa", "bb", "cc", so the answer is 6. - For
s = "abbac"
, only "bb" forms a valid pair, so the answer is 2. - For
s = "abcde"
, no valid adjacent pair exists so the answer is 0.
The solution should take the input from standard input (stdin) and produce the output to standard output (stdout).
inputFormat
The input consists of a single line containing a non-empty string s
composed of lowercase English letters.
outputFormat
Output a single integer—the maximum length of a consecutive segment of s
in which every adjacent pair of characters are the same.
aabbcc
6