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:
true
💡 Note:
The string "carerac" has character frequencies: 'c'=2, 'a'=2, 'r'=2, 'e'=1. Only one character ('e') has an odd frequency, so a palindrome can be formed, for example "caracer".
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code