-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcdfq4feb3.cpp
More file actions
48 lines (43 loc) · 916 Bytes
/
cdfq4feb3.cpp
File metadata and controls
48 lines (43 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
int main()
{
int samples;
cin >> samples;
while (samples--)
{
int n;
cin >> n;
string s;
cin >> s;
int a[n];
int b[n];
int disfirst = 0, dislast = 0;
map<int, int> map1;
map<int, int> map2;
for (int i = 0; i < n; i++)
{
if (map1[s[i]] == 0)
{
disfirst++;
}
a[i] = disfirst;
map1[s[i]]++;
}
for (int i = n - 1; i >= 0; i--)
{
if (map2[s[i]] == 0)
{
dislast++;
}
b[i] = dislast;
map2[s[i]]++;
}
int maximum = INT_MIN;
for (int i = 0; i < n - 1; i++)
{
maximum = max(maximum, a[i] + b[i + 1]);
}
cout << maximum << endl;
}
}