InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Alternate Lower Upper Sort

Problem Description

Given a string A containing lowercase and uppercase letters.

You need to sort it in such a manner such that the uppercase and lowercase letter comes in an alternate manner but in sorted way.

See the example Input and Output for better explanation.



Problem Constraints

1 <= |A| <= 105



Input Format

First argument is an string A.



Output Format

Return a string such that the uppercase and lowercase letter in A comes in an alternate manner but in sorted way.



Example Input

Input 1:

  A = "bAwutndekWEdkd"

Input 2:

  A = "bbBBaa"

Input 3:

  A = "abbfDDhGFBvdFDGBNDasZVDFjkb"



Example Output

Output 1:

 "AbEdWddekkntuw"

Output 2:

 "BaBabb"

Output 3:

 "BaBaDbDbDbDdDfFhFjFkGsGvNVZ"



Example Explanation

Explanation 1:

 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 
 alternatively in the string as far as possible.

Explanation 2:

 Here we can see that letter 'B' and 'B'are sorted as well as characters "a, a, b, b" are sorted but both appears
 alternatively in the string as far as possible.



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Alternate Lower Upper Sort on Interview Code Editor
Sign Up
to access hints and editorial solutions for Alternate Lower Upper Sort

Discussion


Loading...
Click here to start solving coding interview questions