forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
53 lines (38 loc) · 1.04 KB
/
solution.cpp
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
50
51
52
#include <bits/stdc++.h>
using namespace std;
// Implementation Part
int makingAnagrams(string s1, string s2) {
// creating vector for finding frequency of letters
vector<int> freq(26, 0);
// Get the frequency of each letter in s1
for(int i = 0; i < s1.size(); i++){
int index = (int)s1[i] - 97;
freq[index]++;
}
// getting difference of frequency of letters in s1 and s2
for(int i = 0; i < s2.size(); i++){
int index = (int)s2[i] - 97;
freq[index]--;
}
/*
* So if frequency is 0 thet means letter has same frequency in s1 and s2
* no need to delete
* if frequency is not zero...we need to delete that element
*/
int count = 0;
for(int i = 0; i < 26; i++)
count += abs(freq[i]);
return count;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s1;
getline(cin, s1);
string s2;
getline(cin, s2);
int result = makingAnagrams(s1, s2);
fout << result << "\n";
fout.close();
return 0;
}