Palindrome Permutation

You are given a string 'S', check if there exists any permutation of the given string that is a palindrome.

Note :

1. A palindrome is a word or phrase that reads the same from forward and backward e.g. “aba”, it reads the same from forward and backward.
2. A permutation is a rearrangement of letters.
3. The palindrome does not need to be limited to just dictionary words.

Example :

Given string S : aab
The output should be "True" as "aba" (permutation of string S) is a palindrome. 
Input Format :
The first line of the input contains an integer 'T' denoting the number of test cases.

The first and the only line of each test case contains one string 'S'.
Output Format :
For each test case print in a new line, “True” if any permutation of the string is a palindrome or “False” if none of the permutations of the given string are palindrome.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= Length of the given string <= 10^5
It is guaranteed that all the characters in the strings are lower case english alphabets.

Time Limit : 1sec
CodingNinjas
author
2y

A set of characters can form a palindrome if at most one character occurs odd number of times and all characters occur even number of times.

This can be done in O(n) time using a count array.
Steps :
1...read more

CodingNinjas
author
2y
Frequency Table
  1. The idea behind this approach is that in a palindrome at max 1 character can have an odd frequency.
  2. So in this approach, we calculate the frequency of each character of the given string ...read more
CodingNinjas
author
2y
Bit Manipulation
  1. The idea behind this approach is the same as the last approach that in a palindrome, at max 1 character can have an odd frequency.
  2. But in this approach, we will not be storing the frequ...read more
Add answer anonymously...
Hike Android Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter