easy +5 pts

Sort characters alphabetically

Return a string with all characters sorted alphabetically by their ASCII value.

Write a function `sort_characters(s: str) -> str` that takes an input string `s` and returns a new string where all characters are sorted in ascending order according to their ASCII values. The sorting should be case-sensitive: uppercase letters (A-Z) come before lowercase letters (a-z). Spaces and punctuation are also sorted by ASCII value. The original string is not modified. If the input string is empty, return an empty string.

Constraints

The input string can contain any printable ASCII characters. The length of the string is between 0 and 1000. The time complexity should be O(n log n), where n is the length of the string.

Example

>>> sort_characters('hello')
'ehllo'
>>> sort_characters('Python')
'Phnoty'
>>> sort_characters('')
''
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

You can convert the string to a list of characters, sort the list, and then join it back into a string.
Python's built-in `sorted()` function sorts by ASCII value by default.
Remember that an empty string should return an empty string.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.