#C701. Maximum Length of Alternating Substring
Maximum Length of Alternating Substring
Maximum Length of Alternating Substring
In this problem, you are given a string consisting of lowercase English letters. Your task is to determine the maximum length of a substring that can be obtained by selecting characters in order from the input string such that no two adjacent characters in the resulting substring are the same.
A substring here is a contiguous sequence of characters. In order to form an alternating substring, you start with the first character and then include any subsequent character only if it is different from the previous one added to the substring.
The mathematical formulation for the substring length (L) is given by:
(L = 1 + \sum_{i=1}^{n-1} \mathbf{1}_{{s[i] \neq s[i-1]}}), where (\mathbf{1}) is the indicator function.
inputFormat
The input begins with an integer (t) representing the number of test cases. Each test case consists of two lines. The first line contains an integer (n), the length of the string, and the second line contains the string (s) (which is of length (n) and consists of lowercase English letters).
outputFormat
For each test case, output a single integer on a new line representing the maximum length of a substring where no two adjacent characters are the same.## sample
3
4
abac
5
aaaaa
6
abcabc
4
1
6
</p>