#K63277. Longest Non-Consecutive Substring Length
Longest Non-Consecutive Substring Length
Longest Non-Consecutive Substring Length
You are given a string s. Your task is to find the length of the longest contiguous substring in which no two consecutive characters are the same. Formally, if the substring is denoted by \( s[i \dots j] \), then for every index \( k \) such that \( i+1 \le k \le j \) it must hold that \( s[k] \neq s[k-1] \). If the string is empty, the answer is 0.
This problem tests your ability to process strings efficiently and handle edge cases such as empty strings.
inputFormat
The first line contains an integer \( T \) denoting the number of test cases. Each of the next \( T \) lines contains a non-negative string \( s \). The string may consist of lowercase letters or may be empty.
outputFormat
For each test case, output a single integer on a new line representing the length of the longest substring in which no two consecutive characters are the same.
## sample3
abababab
aaabbbccc
abcdef
8
2
6
</p>