![]() |
VOOZH | about |
Given a string containing lowercase and uppercase letters. Sort it in such a manner that the uppercase and lowercase letters come in an alternate manner but in a sorted way.
Examples:
Input : bAwutndekWEdkd Output :AbEdWddekkntuw Explanation: Here we can see that letter āAā, āEā, āWā are sorted as well as letters āb, d, d, d, e, k, k, n, t, u, wā are sorted but both appears alternately in the string as far as possible. Input :abbfDDhGFBvdFDGBNDasZVDFjkb Output :BaBaDbDbDbDdDfFhFjFkGsGvNVZ
1) Count lower case characters in an array lCount[]
2) Count upper case characters in another array uCount[]
3) Modify strings using lCount[] and uCount[]
Output:
AbEdWddekkntuw
Time Complexity: O(n).
Auxiliary Space: O(max(n,26)), where n is the length of the string.
This is because when string is passed in the function it creates a copy of itself in stack.