#K74317. Longest Stable Group in Migration Patterns
Longest Stable Group in Migration Patterns
Longest Stable Group in Migration Patterns
In this problem, you are given several strings representing bird migration patterns. A stable group is defined as a maximal contiguous substring where all characters are identical. Formally, for a string \( S \), a stable group is a substring \( S[i \ldots j] \) (with \( 0 \le i \le j < |S| \)) such that for every \( k \) with \( i < k \le j \), \( S[k] = S[i] \), and either \( i = 0 \) or \( S[i-1] \neq S[i] \), and either \( j = |S|-1 \) or \( S[j] \neq S[j+1] \). Your task is to compute the length of the longest stable group for each migration pattern.
Example: For the string "aaaabbbc", the stable groups are "aaaa", "bbb", and "c". The longest group has length 4.
inputFormat
The first line of the input contains an integer ( T ) (the number of test cases). Each of the following ( T ) lines contains a non-empty string representing a bird migration pattern.
outputFormat
For each test case, output a single line containing a single integer — the length of the longest stable group in the given migration pattern.## sample
3
aabbcc
aaaabbbc
abcd
2
4
1
</p>