Join millions of students and teachers in over 180 countries starting with an Hour of Code. Therefore, we can solve this by counting the number of occurrences of each character with a dictionary.Įach there is at most 1 character that appears an odd number of times, then that means the string can be rearranged as a palindrome. Hour of Code Activities Try a one-hour tutorial designed for all ages in over 45 languages. That means that either every character has a matching pair, or there is one character that appears an odd number of times (and that character must be placed in the middle of the string). In other words, a palindrome is a string that can be reversed to produce the same string. Have an odd number of characters, where there’s only one character that appears an odd number of times You should write a couple of palindromes down and see if you can notice any patterns. In order to solve this, we need to think about the properties of a palindrome. Output - True (the letters can be rearranged to “racecar”) Write a function that checks if the letters in the string can be rearranged to form a palindrome ( or if the input is already a palindrome). As a refresher, here’s the previous question