Skip to content

Practice Smallest Palindromic Rearrangement II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3518
LeetCode Problem

Smallest Palindromic Rearrangement II

Problem Statement

You are given a palindromic string s and an integer k. Return the k-th lexicographically smallest palindromic permutation of s. If there are fewer than k distinct palindromic permutations, return an empty string. Note: Different rearrangements that yield the same palindromic string are considered identical and are counted once.

Source: Smallest Palindromic Rearrangement II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abba", k = 2
Output
"baab"

# Example 2

Input
s = "aa", k = 2
Output
""

# Example 3

Input
s = "bacab", k = 1
Output
"abcba"

Constraints

1 <= s.length <= 10^4
s consists of lowercase English letters.
s is guaranteed to be palindromic.
1 <= k <= 10^6

Related LeetCode Problems

Practice more problems similar to Smallest Palindromic Rearrangement II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.