Test time left: 33:41Write the codeTake the input as string from the user, If any permutation of the word is palindrome then return "True" or else return "False"For example : "carrace" should return "True", since it can be rearranged to form "racecar", which is a palindrome."daily" should return "False", since there's no rearrangement that can form a palindrome.Sample Test CasesTest Case 1:Expected Output:Enter·the·word:·dyyadaTrueTest Case 2:Expected Output:Enter·the·word:·carraceTrueTest Case 3:Expected Output:Enter·the·word:·daisyFalse
Question
Test time left: 33:41Write the codeTake the input as string from the user, If any permutation of the word is palindrome then return "True" or else return "False"For example : "carrace" should return "True", since it can be rearranged to form "racecar", which is a palindrome."daily" should return "False", since there's no rearrangement that can form a palindrome.Sample Test CasesTest Case 1:Expected Output:Enter·the·word:·dyyadaTrueTest Case 2:Expected Output:Enter·the·word:·carraceTrueTest Case 3:Expected Output:Enter·the·word:·daisyFalse
Solution
Sure, here is a Python solution for the problem:
def check_palindrome(word):
count = [0]*256
odd = 0
for i in range(0, len(word)):
count[ord(word[i])] += 1
for i in range(0, 256):
if (count[i] & 1):
odd += 1
if (odd > 1):
return False
return True
word = input("Enter the word: ")
if(check_palindrome(word)):
print("True")
else:
print("False")
This code works by counting the frequency of each character in the word. If more than one character has an odd count, then a palindrome cannot be formed, and the function returns False. If all characters have an even count, or exactly one character has an odd count, then a palindrome can be formed, and the function returns True.
Similar Questions
Palindrome CheckerReturn true if the given string is a palindrome. Otherwise, return false.A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.Note: You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.We'll pass strings with varying formats, such as racecar, RaceCar, and race CAR among others.We'll also pass strings with special symbols, such as 2A3*3a2, 2A3 3a2, and 2_A3*3#A2.
"Please create a pseudocode function that will check if all the words in an array are palindromes. For example, an input of ['racecar', 'noon', 'civic'] should return True, but an input of ['racecar', 'shoe', 'moon'] should return False."
word = input("enter a word") word = word.lower() turd = len(word) for i in range(0,turd,1): if word[i] == word[turd-i]: print("palindrome") else: print("no") palindrome()
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.Given a string s, return true if it is a palindrome, or false otherwise. Example 1:Input: s = "A man, a plan, a canal: Panama"Output: trueExplanation: "amanaplanacanalpanama" is a palindrome.Example 2:Input: s = "race a car"Output: falseExplanation: "raceacar" is not a palindrome.Example 3:Input: s = " "Output: trueExplanation: s is an empty string "" after removing non-alphanumeric characters.Since an empty string reads the same forward and backward, it is a palindrome. Constraints:1 <= s.length <= 2 * 105s consists only of printable ASCII characters.
Write a Java program to check whether a given word is a palindrome or not. for e.g. MADAM is a palindrome but eat is not.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.