-
Notifications
You must be signed in to change notification settings - Fork 3
/
Day-33
49 lines (39 loc) · 1.1 KB
/
Day-33
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
49
int lis(vector<int> v)
{
vector<int> lis;
for(int i=0;i<v.size();i++)
{
auto it = lower_bound(lis.begin(), lis.end(), v[i]);
if(it!=lis.end())
*it=v[i];
else
lis.push_back(v[i]);
}
return lis.size();
}
int minInsAndDel(int a[], int b[], int n, int m) {
// code here
unordered_map<int,int> mb;
int count;
for(int i=0;i<m;i++)
{
mb[b[i]]++;
}
vector<int> new_a;
for(int i=0;i<n;i++)
{
if(mb.find(a[i])!=mb.end())
new_a.push_back(a[i]);
}
//step 1
// deletion of those element which are not in b but present in a
count=n-new_a.size() ;
int lis_length=lis(new_a);
// step 2
// deletion of those element which are not in increasing sequence
count=count + new_a.size()-lis_length;
// step 3
// insertion of those element which are not in above lis sequence
count =count + m-lis_length;
return count;
}