You are given a string ss of length nn, where each character is either < or >.
An array aa consisting of n+1 elements is compatible with the string ss if, for every i from 1 to nn, the character sisi represents the result of comparing aiai and ai+1, i. e.:
- si is < if and only if ai<ai+1
- si is > if and only if ai>ai+1
For example, the array [1,2,5,4,2] is compatible with the string <<>>. There are other arrays with are compatible with that string, for example, [13,37,42,37,13]
The cost of the array is the number of different elements in it. For example, the cost of[1,2,5,4,2] is 4; the cost of [13,37,42,37,13] is 3.
You have to calculate the minimum cost among all arrays which are compatible with the given string ss.
Input
The first line contains one integer tt (1≤t≤500) — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer n (1≤n≤100);
- the second line contains the string ss, consisting of n characters. Each character of s is either < or >.
Output
For each test case, print one integer — the minimum cost among all arrays which are compatible with the given string s
#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t--)
{
cin >> n;
cin >> s;
int cnt = 1;
int ans = cnt;
for(int i = 1; i < n;i++)
{
if(s[i] == s[i - 1])
{
cnt++;
}
else
{
cnt = 1;
}
ans = max(cnt,ans);
}
cout << ans + 1 << endl;
}
return 0;
}