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.
Game Of Thrones - II
Game Of Thrones - II
Sort by
recency
|
24 Discussions
|
Please Login in order to post a comment
My Solution in Python :
ruby:
Well, how can u make a palindrome by suffling the string? At most one letter can be odd, else You can't. *so return -1 for such cases.* Now move on to the logic. first u need to make a frequency array and know that which letter came how many times *Now, to deal with the permutation. You have to worry about the left part, because if you know the left part, right one will be fixed, it will be just reversed* So, you have total length N, but u have to deal only half, so number of blanks to be filled with rotations = factorial(N/2) *Make sure to take only int of N/2* Now, you have some letters to filled in N/2 blanks, but since each letter has its frequency, and we are caring only half side, so we will care only half of each letters count *for example, if 'a' came 10 time, and 'b' came 5 times, we care only 5, and 2 respectively (Note, since we have no more than 1 letter odd, the odd part of letter will be fixed in the middle for forever, thus we never gonna count on odd here)* ans = factorial(N/2)/factorial(each letters count/2) **for example. if count of 'a' is 10, 'b' is '6' and 'c' is '3' time in a string then, ans = 9!/(5!*3!1!)*
My testcases 31 to 40 give wrong answer. I'm not sure why. Could someone please help. :)