Education + Jobs Hiring Website - 2025
0 like 0 dislike
2,914 views
in Online Assessments by Expert (44,360 points) | 2,914 views

1 Answer

0 like 0 dislike

Given a string word as input, return the minimum number of characters added into the word to become anagram - become a palindrome.

For example, if word = "apple", it's possible to add two letters 'a' and 'e', which makes the resulting string an anadrome: "appleae" letters can be rearranged to become "apelepa", which is a palindrome.

by Expert (44,360 points)
0 0
//what about this code?
//my intuition is  ,to make a word palindrome we should have even count of characters except which comes in middle of word
so we simply count no of odd occuring characters and we increment all those characters except 1..


int main()
{
    string s="apple";
    unordered_map<char,int>count;
    for(auto i:s)
    {
        count[i]++;
    }
    int res=0;
    for(auto i:count)
    {
        if(i.second%2!=0)
        {
            res++;
        }
    }
    cout<<res-1;
    
}