Making Anagrams

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/B4pZbX0VzzU

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        string fstr, sstr;
        cin >> fstr; cin >> sstr;
        vector<int>fsc(26,0), ssc(26,0);
        int i, result = 0;
        for(i = 0; i < fstr.size(); i++) fsc[fstr[i] - 'a']++;
        for(i = 0; i < sstr.size(); i++) ssc[sstr[i] - 'a']++;
        for(i = 0; i < 26; i++) result += abs(fsc[i] - ssc[i]);
        cout << result << endl;
        return 0;
    }