C++ || 2 DIFFIERENT APPROACHS || ARRAY AND HASHMAP || EASY
--->Here\'s a step-by-step explanation of the code:\n\n1-The program starts by defining a function longestPalindrome that   takes a string s as input and return
--->Here\'s a step-by-step explanation of the code:\n\n1-The program starts by defining a function longestPalindrome that   takes a string s as input and returns an integer.\n\n2-It first checks if the length of the string is 1. If it is, then it returns 1 because a palindrome of length 1 can be formed using a single character.\n\n3-It declares a variable count to keep track of the number of characters with an odd count.\n\n4-It then declares an integer array arr of size 256 (which is the number of ASCII characters) and initializes all the elements to 0.\n\n5-It then loops through each character in the input string s and increments the corresponding element in the arr array.\n\n6-After counting the occurrence of each character, it loops through each element in the arr array and checks if the count of that character is odd. If it is, then it increments the count variable.\n\n7-After counting the number of characters with an odd count, it checks if the count is greater than 1. If it is, then it subtracts the odd count from the length of the string and adds 1 to get the length of the longest palindrome that can be formed. Otherwise, it returns the length of the string as it is.\n\n8-The program then returns the length of the longest palindrome that can be formed.\n\nOverall, the program is an efficient way to find the length of the longest palindrome that can be formed using the characters of a given string. It has a time complexity of O(n) and a space complexity of O(1), where n is the length of the input string.\n\nUPVOTE IF YOU FIND IT INTERESTING \nJAI SHREE RAM\n\n\n# Code\n```\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        //CREATE A ARRAY OF SIZE ALL ASCII VALUES AND ADD THE OCCURANCE OF ALL THE CHARACTER THIER \n        if(s.length()==1){\n            return 1;\n        }\n        int count=0;\n        \n        int arr[256]={0};\n        for(int i=0;i<s.length();i++){\n          //STORE THE VALUES AND THIER COUNT\n            arr[s[i]]++;\n        }\n        for(int i=0;i<256;i++){\n            if(arr[i]%2==1){\n              //COUNT THE NUMBER OF ODD ALPHABHET\n                    count++;\n            }\n        }\n        if(count>1){\n          //IF ODD COUNT IF GREATER  THAN  1 THAT MEAN IT HAS MORE THAN 1 CHARACTER WITH ODD COUNT SO WE CAN YOU ONLY ONE SO WILL SUBTRACT THE ODD COUNT AND ADD 1 BECAUSE WE CAN USE ON ODD ALPHABET...\n            return s.length()-count+1;\n        }\n        return s.length();\n\n//____________________________________________________________________________\n//________________________________________________________________________________________________________________________________________\n        //HASHMAP APPROACH SIMPLE ADD VALUES AND THEIR RESPECTIVE COUNT IN HASH MAP AND THAN COUNT THE NUMBER OF ODD COUNT\n        int oddCount = 0;\n        unordered_map<char, int> ump;\n        for(char ch : s) {\n            ump[ch]++;\n        }\n       for(int i=0;i<ump.size();i++){\n           if(ump[i]%2==1){\n               oddCount++;\n           }\n           \n       }\n        cout<<oddCount<<" "<<endl;\n        if (oddCount > 1)\n            return s.length() - oddCount + 1;\n        return s.length();\n      \n    }\n};\n```
['C++']