Case-Segregated String Sort

00:00
Mediumstringsortingarrayscustom-comparator

Given a string s, sort its characters according to the following rules and return the resulting sorted string:

  1. All lowercase English letters must appear first, sorted in alphabetical order ('a' to 'z').
  2. All uppercase English letters must appear next, sorted in alphabetical order ('A' to 'Z').
  3. All digits must appear last, sorted in ascending order ('0' to '9').
  4. Any spaces in the original string must be completely removed.

Constraints:

  • 0 <= s.length <= 10^4
  • s consists of English letters, digits, and spaces.

Examples

Input → "bA1 cB2"
Output → "abcAB12"
Explanation:

Lowercase letters 'b', 'c', 'a' are sorted to 'abc'. Uppercase letters 'A', 'B' are sorted to 'AB'. Digits '1', '2' are sorted to '12'. Spaces are removed.

Input → "Sorting"
Output → "ginorSt"
Explanation:

Lowercase letters 'o', 'r', 't', 'i', 'n', 'g' sorted to 'ginort'. Uppercase 'S' remains as is. Final output is 'ginorSt'.

Input → " "
Output → ""
Explanation:

All spaces are ignored, resulting in an empty string.