feat: add solution for smallest palindromic rearrangement ii
- add problem 3518 implementation - add build configuration with debug and release modes - add test cases and examples - add makefile for problem-specific build workflow
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# 3518. Smallest Palindromic Rearrangement II
|
||||
|
||||
You are given a string `s` and an integer `k`.
|
||||
|
||||
Return the k-th palindromic 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.
|
||||
|
||||
## Example 1
|
||||
|
||||
**Input:**
|
||||
|
||||
```text
|
||||
s = "abba", k = 2
|
||||
````
|
||||
|
||||
**Output:**
|
||||
|
||||
```text
|
||||
"baab"
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
The two distinct palindromic rearrangements of `"abba"` are `"abba"` and `"baab"`.
|
||||
|
||||
Lexicographically, `"abba"` comes before `"baab"`. Since `k = 2`, the output is `"baab"`.
|
||||
|
||||
## Example 2
|
||||
|
||||
**Input:**
|
||||
|
||||
```text
|
||||
s = "aa", k = 2
|
||||
```
|
||||
|
||||
**Output:**
|
||||
|
||||
```text
|
||||
""
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
There is only one palindromic rearrangement: `"aa"`.
|
||||
|
||||
The output is an empty string since `k = 2` exceeds the number of possible rearrangements.
|
||||
|
||||
## Example 3
|
||||
|
||||
**Input:**
|
||||
|
||||
```text
|
||||
s = "bacab", k = 1
|
||||
```
|
||||
|
||||
**Output:**
|
||||
|
||||
```text
|
||||
"abcba"
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
The two distinct palindromic rearrangements of `"bacab"` are `"abcba"` and `"bacab"`.
|
||||
|
||||
Lexicographically, `"abcba"` comes before `"bacab"`. Since `k = 1`, the output is `"abcba"`.
|
||||
|
||||
## Constraints
|
||||
|
||||
* `1 <= s.length <= 104`
|
||||
* `s` consists of lowercase English letters.
|
||||
* `s` is guaranteed to be palindromic.
|
||||
* `1 <= k <= 106`
|
||||
Reference in New Issue
Block a user