Sort String with alternate lower upper.
Given a string ‘STR’ containing lowercase and uppercase letters. You need to sort the string so that the resulting string contains uppercase and lowercase letters at alternate positions but in sorted order.
Note
If any lowercase or uppercase letters remains left after alternate positioning, then append them at the last of the string in sorted order.
For Example
If the given string STR = “rDaBfS” then after sorting STR = “aBfDrS”. In the sorted string, lowercase letters a,f,r, and uppercase letters B, D, S are in sorted order and alternate positions.
Input Format
The first line contains ‘T’, denoting the number of test cases.
The first line of each test contains a string 'STR' containing lowercase and uppercase letters.
Output Format
For each test case, print a single line containing a single string denoting the sorted string having the lower case or uppercase letters at alternate positions.
The output for each test case will be printed in a separate line.
Note:
You don't have to print anything. It has already been taken care of. Just implement the given function.
Constraints
1 <= T <= 10
1 <= |STR| <= 10 ^ 5
Where ‘T’ is the number of test cases and |STR| is the string’s length.
Time limit: 1 sec.
CodingNinjas
author
2y
Brute Force Approach
- We will solve this problem by taking two arrays, ‘upCount’ and ‘lowCount’ of size ‘26’ that will store the count of uppercase and lowercase letters.
- We will traverse the given strin...read more
Help your peers!
Add answer anonymously...
Top uCertify Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app