Can any help me with the palindrome reorder problem on CSES

Hello all,
I am trying to solve the palindrome partitioning problem in CSES and have written the below code

#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
using namespace std;

int main() {

    string str;
    cin >> str;

    map<char,int> hashmap;

    for(char ch: str) {
        hashmap[ch]++;
    }

    int oddCount = 0;

    map<char,int>::iterator itr;
    for(itr = hashmap.begin(); itr != hashmap.end(); itr++) {
        int count = itr->second;

        if (count%2 != 0) {
            oddCount++;

            if (oddCount > 1) {
                cout << "NO SOLUTION" ;
                return 0;
            }
        }
    }

    string answer;

    char oddChar ;

    for(itr = hashmap.begin(); itr != hashmap.end(); itr++) {
        int currentCount = itr->second;

        // if odd count 
        if (currentCount % 2 != 0) {
            oddChar = itr->first;
        }

        currentCount = currentCount/2;

        char currentChar = itr->first;

        while(currentCount--) {
            answer += currentChar;
        }
    }

    string reverseAnswer = answer;
    reverse(reverseAnswer.begin(), reverseAnswer.end());

    answer = answer + oddChar + reverseAnswer;

    cout << answer;
}

I don’t know why it is showing the wrong answers for some test cases when my output and correct output are the same

Screenshot from 2021-12-26 14-59-35

Screenshot from 2021-12-26 14-59-38

Thank you in advance :slight_smile:

Here in the odd char you have not initialised it suppose you do not have odd value of a character than what will you print initialised with some letter or hyphen and check if it is not that value than only print the character otherwise only print answer + reverse answer