Case-specific Sorting of Strings
Submissions: 2438   Accuracy:

51.24%

  Difficulty: Medium   Marks: 4
Associated Course(s):   Geeks Classes in Noida

Given a string S consisting of uppercase and lowercase characters. The task is to sort uppercase and lowercase characters separately such that if the ith place in the original string had an uppercase character then it should not have a lowercase character after being sorted and vice versa.

Input:
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the length of string.
The second line contains a string S of length N, consisting of uppercase and lowercase characters.

Output:
For each testcase, print the sorted string.

Constraints:
1 ≤ T ≤ 50
1 ≤ N ≤ 103

Example:
Input:
2
12
defRTSersUXI
6
eDefSR

Output:
deeIRSfrsTUX
eDefRS

Explanation:
Testcase 1:
Sorted form of given string with the same case of character as that in original string.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Ganesh Sawhney


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.