-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMINLCS.cpp
More file actions
48 lines (47 loc) · 777 Bytes
/
MINLCS.cpp
File metadata and controls
48 lines (47 loc) · 777 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
// https://www.codechef.com/START61C/problems/MINLCS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(string s, string s1, int n)
{
map<char, ll> f, fa;
for (auto u : s)
{
f[u]++;
}
for (auto u : s1)
{
fa[u]++;
}
ll mn = 0;
for (ll i = 0; i < s.size(); i++)
{
if (f[s[i]] > 0 && fa[s[i]] > 0)
{
ll a = min(f[s[i]], fa[s[i]]);
mn = max(mn, a);
}
}
if (mn == 0)
{
cout << 0 << endl;
}
else
{
cout << mn << endl;
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s, s1;
cin >> s >> s1;
solve(s, s1, n);
}
return 0;
}