欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1552A.Subsequence Permutation
Subsequence Permutation
A string of length , consisting of lowercase letters of the English alphabet, is given.
You must choose some number between and . Then, you select characters of and permute them however you want. In this process, the positions of the other characters remain unchanged. You have to perform this operation exactly once.
For example, if , you can choose the characters "a_d_ea" and permute them into "d_e_aa" so that after the operation the string becomes "dneraa".
Determine the minimum so that it is possible to sort alphabetically (that is, after the operation its characters appear in alphabetical order).
Input
The first line contains a single integer () — the number of test cases. Then test cases follow.
The first line of each test case contains one integer () — the length of the string.
The second line of each test case contains the string . It is guaranteed that contains only lowercase letters of the English alphabet.
Output
For each test case, output the minimum that allows you to obtain a string sorted alphabetically, through the operation described above.
Note
In the first test case, we can choose the characters "_ol" and rearrange them as "_lo" (so the resulting string is "llo"). It is not possible to sort the string choosing strictly less than characters.
In the second test case, one possible way to sort is to consider the characters "_o__force_" and rearrange them as "_c__efoor_" (so the resulting string is "ccdeefoors"). One can show that it is not possible to sort the string choosing strictly less than characters.
In the third test case, string is already sorted (so we can choose characters).
In the fourth test case, we can choose all characters "dcba" and reverse the whole string (so the resulting string is "abcd").
Samples
4
3
lol
10
codeforces
5
aaaaa
4
dcba
2
6
0
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |