Upload code_segments/segment_234.txt with huggingface_hub
Browse files
code_segments/segment_234.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Turtle gives you a string $s$, consisting of lowercase Latin letters.
|
| 2 |
+
|
| 3 |
+
Turtle considers a pair of integers $(i, j)$ ($1 \le i < j \le n$) to be a pleasant pair if and only if there exists an integer $k$ such that $i \le k < j$ and both of the following two conditions hold:
|
| 4 |
+
|
| 5 |
+
* $s_k \ne s_{k + 1}$; * $s_k \ne s_i$ or $s_{k + 1} \ne s_j$.
|
| 6 |
+
|
| 7 |
+
Besides, Turtle considers a pair of integers $(i, j)$ ($1 \le i < j \le n$) to be a good pair if and only if $s_i = s_j$ or $(i, j)$ is a pleasant pair.
|
| 8 |
+
|
| 9 |
+
Turtle wants to reorder the string $s$ so that the number of good pairs is maximized. Please help him!
|
| 10 |
+
|
| 11 |
+
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
|
| 12 |
+
|
| 13 |
+
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the string.
|
| 14 |
+
|
| 15 |
+
The second line of each test case contains a string $s$ of length $n$, consisting of lowercase Latin letters.
|
| 16 |
+
|
| 17 |
+
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
| 18 |
+
|
| 19 |
+
For each test case, output the string $s$ after reordering so that the number of good pairs is maximized. If there are multiple answers, print any of them.
|
| 20 |
+
|
| 21 |
+
In the first test case, $(1, 3)$ is a good pair in the reordered string. It can be seen that we can't reorder the string so that the number of good pairs is greater than $1$. bac and cab can also be the answer.
|
| 22 |
+
|
| 23 |
+
In the second test case, $(1, 2)$, $(1, 4)$, $(1, 5)$, $(2, 4)$, $(2, 5)$, $(3, 5)$ are good pairs in the reordered string. efddd can also be the answer.
|