VOOZH about

URL: https://www.geeksforgeeks.org/dsa/alternate-lower-upper-string-sort/

⇱ Alternate Lower Upper String Sort - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Alternate Lower Upper String Sort

Last Updated : 22 Jun, 2022

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
Recommended Practice

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.

Comment
Article Tags: