Rearrange a string
Easy Accuracy: 70.41% Submissions: 1772 Points: 2

Given a string containing uppercase alphabets and integer digits (from 0 to 9), the task is to print the alphabets in the lexicographical order followed by the sum of digits.

Example 1:

Input: S = "AC2BEW3"
Output: "ABCEW5"
Explanation: 2 + 3 = 5 and we print all
alphabets in the lexicographical order. 

Example 2:

Input: S = "ACCBA10D2EW30"
Output: "AABCCDEW6"
Explanation: 0+1+2+3 = 6 and we print all
alphabets in the lexicographical order. 

Your Task:  
You don't need to read input or print anything. Your task is to complete the function arrangeString() which takes the string as inputs and returns the modified string.

Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(26)

1 ≤ |S| ≤ 105
S contains only upper case alphabets and digits.

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Rearrange a string

Output Window