We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Game of Thrones - I
- Discussions
Game of Thrones - I
Game of Thrones - I
Sort by
recency
|
1084 Discussions
|
Please Login in order to post a comment
Here is my c++ solution : explanation here : https://youtu.be/yhSaL48IHds
solution 1 :
solution 2 :
Approach to solve:
1 Count Character Frequencies Use a hash map (unordered_map) or array (int freq[26]) to store how many times each character appears in the given string.
2 Count Odd Frequency Characters Traverse through the frequency table and count how many characters have an odd frequency.
3 Check Conditions for a Palindrome If odd frequency count <= 1, the string can be rearranged into a palindrome --> Return "YES". Otherwise, return "NO".
Here is my Python solution!
string gameOfThrones(string s) { map mp; for(char i:s){ mp[i]++; } int count =0; for(int i=0;i1)return "NO"; else return "YES"; }