You are viewing a single comment's thread. Return to all comments →

Figure out whether any anagram of the string can be a palindrome or not.

A palindrome of even length should have all character counts even. A palindrome of odd length should have all but one character counts even.

the given input string contains only lower case english letters, which are 26 of them. I am masking the bits for each character occurences.

let me take an example:

If our given string is even length palindrome then "mask" will always be zero going by above logic.

If our given string is odd length palindrome then "mask" will always be power of 2 (to check if given integer is power of 2 :-> (n & (n - 1) == 0)).

hope it helps.

yup , got it.. thanks for help.

## Game of Thrones - I

You are viewing a single comment's thread. Return to all comments →

Figure out whether any anagram of the string can be a palindrome or not.A palindrome of even length should have all character counts even. A palindrome of odd length should have all but one character counts even.

the given input string contains only lower case english letters, which are 26 of them. I am masking the bits for each character occurences.

let me take an example:

abba:- Here we have 2 occurences of 'a' and 'b'.abcba:- Here we have 2 occurneces of 'a' and 'b' and one occurence of 'c'.If our given string is even length palindrome then "mask" will always be zero going by above logic.

If our given string is odd length palindrome then "mask" will always be power of 2 (to check if given integer is power of 2 :-> (n & (n - 1) == 0)).

hope it helps.

yup , got it.. thanks for help.