# HackerRank ‘Game of Thrones – I’ Solution

H
##### Short Problem Definition:

Dothraki are planning an attack to usurp King Robert from his kingdom. King Robert learns of this conspiracy from Raven and plans to lock the single door through which an enemy can enter his kingdom. But, to lock the door he needs a key that is an anagram of a certain palindrome string.

Game of Thrones – I

##### Complexity:

time complexity is O(N);

space complexity is O(1)

##### Execution:

A palindrome must by definition have an even number of letters. The only exception is a string of an odd length (‘aba’) that has exactly one odd letter count.

##### Solution:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 `#!/usr/bin/py` `if` `__name__ ``=``=` `'__main__'``:` `    ``string ``=` `raw_input``()` `    ``found ``=` `True` `    ``# Write the code to find the required palindrome and then assign the variable 'found' a value of True or False` `    ``oddCnt ``=` `0` `    ``letterCnt ``=` `[``0``] ``*` `26` `    `  `    ``for` `letter ``in` `string:` `        ``letterCnt[``ord``(letter)``-``ord``(``'a'``)] ``+``=` `1` `    `  `    ``for` `cnt ``in` `letterCnt:` `        ``oddCnt ``+``=` `cnt ``%` `2` `        `  `    ``if` `oddCnt > ``1``:` `        ``found ``=` `False`   `    ``if` `not` `found:` `        ``print``(``"NO"``)` `    ``else``:` `        ``print``(``"YES"``)`

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 `#include ` `#include ` `#include ` `#include ` `#include ` `#include ` `using` `namespace` `std;`     `int` `main() {` `   `  `    ``string s;` `    ``cin>>s;` `     `  `    ``int` `flag = 1;` `    `  `    ``int` `oddCnt = 0;` `    ``int` `letterCnt[26] = {};` `        `  `    ``for` `(``int` `i=0; i 1){` `        ``flag = 0;` `    ``}` `    `  `    ``// Assign Flag a value of 0 or 1 depending on whether or not you find what you are looking for, in the given string ` `    ``if``(flag==0)` `        ``cout<<``"NO"``;` `    ``else` `        ``cout<<``"YES"``;` `    ``return` `0;` `}`