easy +8 pts

Sort characters in string

Rearrange the characters of a given string in sorted order and return the result.

Write a function `sort_string(s: str) -> str` that takes a string `s` and returns a new string with all characters sorted in ascending order based on their Unicode code points. The function must not modify the original string. If the input string is empty, return an empty string. The sorting is case-sensitive: uppercase letters come before lowercase letters (e.g., 'Z' < 'a'). You may use any standard sorting method, but you must not use external libraries.

Constraints

The input string length is between 0 and 10^5. The characters are any printable ASCII characters (code points 32–126). The function should handle the input in O(n log n) time and O(n) extra space.

Example

>>> sort_string('hello')
'ehllo'
>>> sort_string('Python')
'Phnoty'
>>> sort_string('')
''
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the built-in `sorted` function which returns a list of characters in sorted order.
Join the sorted list of characters back into a string using the `join` method.
Remember to handle the empty string case naturally.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.