Check whether a string can be rearranged into a palindrome

Quick Overview

Decide whether the letters of a lowercase string can be reordered to form a palindrome, using every character exactly once. It tests reasoning about character frequencies, a short correctness argument and a linear-time implementation.

Check whether a string can be rearranged into a palindrome

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given a string `s`, determine whether its characters can be rearranged to form a palindrome. Return `True` if such a rearrangement exists, otherwise return `False`. A palindrome reads the same forward and backward. The rearrangement must use every character of `s` exactly once. ### Function Signature ```python def can_rearrange_palindrome(s: str) -> bool: ``` ### Constraints - `1 <= len(s) <= 10^5` - `s` consists of lowercase English letters only. ### Examples ```text Input: s = "civic" Output: True ``` `"civic"` is already a palindrome, so a valid arrangement exists. Its letters are c twice, i twice and v once, and the single v sits in the middle. ```text Input: s = "hello" Output: False ``` `h`, `e` and `o` each appear once and `l` appears twice. Each lone letter would need a matching copy at the mirrored position, and a palindrome has only one unpaired spot (its middle), so no arrangement works. ```text Input: s = "aabbc" Output: True ``` `"aabbc"` is not a palindrome as written, but it can be rearranged into `"abcba"`.

Overview: Decide whether the letters of a lowercase string can be reordered to form a palindrome, using every character exactly once. It tests reasoning about character frequencies, a short correctness argument and a linear-time implementation.

Amazon logo
Amazon
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given a string s, determine whether its characters can be rearranged to form a palindrome. Return True if such a rearrangement exists, otherwise return False.

A palindrome reads the same forward and backward. The rearrangement must use every character of s exactly once.

Function Signature

def can_rearrange_palindrome(s: str) -> bool:

Constraints

  • 1 <= len(s) <= 10^5
  • s consists of lowercase English letters only.

Examples

Input: s = "civic"
Output: True

"civic" is already a palindrome, so a valid arrangement exists. Its letters are c twice, i twice and v once, and the single v sits in the middle.

Input: s = "hello"
Output: False

h, e and o each appear once and l appears twice. Each lone letter would need a matching copy at the mirrored position, and a palindrome has only one unpaired spot (its middle), so no arrangement works.

Input: s = "aabbc"
Output: True

"aabbc" is not a palindrome as written, but it can be rearranged into "abcba".