788. Palindrome Permutation II

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: "aabb"

Output: ["abba", "baab"]

Explanation:

  • The given string "aabb" has characters with even frequencies ('a' appears twice, 'b' appears twice).
  • Since a palindrome must have at most one character with an odd frequency, a palindromic permutation is possible.
  • The possible palindromic permutations are "abba" and "baab".

Example 2:

Input: "abc"

Output: []

Explanation:

  • The string "abc" has all unique characters ('a', 'b', 'c' each appear once).
  • A palindrome requires at most one character with an odd frequency, but here, all three have odd frequencies.
  • Since no valid palindromic permutation can be formed, the answer is an empty list.

Now Your Turn!

Pick the correct output for the given input

Input: "abccdda"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

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

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
vector<string> generatePalindromes(string s) {
// Your code goes here
}
};
Test Case

Input:

S