Problem 205059 · easy · Phase 02 Linear Data Structures

Shuffle into a Palindrome

strings · palindromes · counting

Write can_shuffle_to_palindrome(s) that returns True if the letters of s can be rearranged to form a palindrome. Ignore every character that is not a letter, and treat uppercase and lowercase as the same letter. A string with no letters counts as True.

Examples

Input:  s = "Taco cat"
Output: True
Explanation: the letters t,a,c,o,c,a,t already form a palindrome.

Input:  s = "abc"
Output: False

Input:  s = "aab"
Output: True
Explanation: "aba".

Constraints

  • 0 <= len(s) <= 10**5, printable ASCII
  • Target: O(n) time

Goals

  • Filter and normalise characters before counting
  • Count character frequencies
  • Reason about which frequency patterns allow a palindrome
Starting Python…