Sort String with Alternate Lower and Upper Case
Given a string STR
containing both lowercase and uppercase letters, the task is to sort the string so that the resulting string contains uppercase and lowercase letters at alternate positions, with each group sorted individually.
Example:
Input:
STR = "rDaBfS"
Output:
"aBfDrS"
Explanation:
The lowercase letters a, f, r and uppercase letters B, D, S are sorted and positioned alternately. Remaining letters, if any, are appended at the end in sorted order.
Input:
'T' representing the number of test cases.
Each test case contains one string 'STR' with lowercase and uppercase letters.
Output:
For each test case, output a single string with alternating lowercase and uppercase letters in sorted order.
Constraints:
- 1 <= T <= 10
- 1 <= |STR| <= 105
- Time limit: 1 sec.
Note:
You don't need to handle printing; the function implementation will manage this task.
Be the first one to answer
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