Palindrome Permutation - Problem
Given a string s, return true if a permutation of the string could form a palindrome and false otherwise.
A palindrome is a word that reads the same forward and backward (e.g., "racecar", "madam").
You need to determine if the characters in the string can be rearranged to form a palindrome, not whether the string itself is already a palindrome.
Example: The string "aab" can be rearranged to "aba", which is a palindrome, so the answer is true.
Input & Output
Example 1 — Can Form Palindrome
$
Input:
s = "aab"
›
Output:
true
💡 Note:
The string "aab" can be rearranged to "aba" which is a palindrome. Character 'a' appears 2 times (even), 'b' appears 1 time (odd). Since at most one character has odd frequency, a palindrome is possible.
Example 2 — Cannot Form Palindrome
$
Input:
s = "carerac"
›
Output:
false
💡 Note:
The string "carerac" has character frequencies: 'c'=2, 'a'=2, 'r'=2, 'e'=1. All characters appear an even number of times except 'e', but we cannot form a palindrome because the arrangement would be unbalanced.
Example 3 — Single Character
$
Input:
s = "a"
›
Output:
true
💡 Note:
A single character is always a palindrome. Character 'a' appears 1 time (odd), which is allowed.
Constraints
- 1 ≤ s.length ≤ 1000
- s consists of lowercase English letters only
Visualization
Tap to expand
Understanding the Visualization
1
Input String
Given string with characters to analyze
2
Count Frequencies
Count how many times each character appears
3
Check Rule
At most one character can have odd count
Key Takeaway
🎯 Key Insight: A palindrome can have at most one character appearing an odd number of times (the middle character)
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code