Talentd
FleetCode

267. Palindrome Permutation II

Medium41.9% acceptancePremium elsewhere, free here

Given a string s, return all the palindromic permutations (without duplicates) of it.

You may return the answer in any order. If s has no palindromic permutation, return an empty list.

Example 1:

Input: s = "aabb"
Output: ["abba","baab"]

Example 2:

Input: s = "abc"
Output: []

Constraints:

  • 1 <= s.length <= 16
  • s consists of only lowercase English letters.

Hints open one at a time

Hint 1
If a palindromic permutation exists, we just need to generate the first half of the string.
Hint 2
To generate all distinct permutations of a (half of) string, use a similar approach from: Permutations II or Next Permutation.
8:00
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
"aabb"
Input
"abc"
Your code is saved on this device.Solution