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
Palindrome Permutation: Can "aab" form a palindrome?aab↓ Count frequencies ↓a: 2(even)b: 1(odd)Rule: At most 1 character can have odd count✓ Only 'b' has odd count → Can form "aba"Result: true
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)
Asked in
Google 25 Facebook 30 Amazon 20 Microsoft 15
125.0K Views
Medium Frequency
~15 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen