easy +10 pts

Remove Duplicate Letters

Remove duplicate characters while preserving the relative order of their first occurrences.

Write a function `remove_duplicate_letters(s: str) -> str` that returns a new string with all duplicate characters removed. The characters in the result should appear in the same order as their first occurrence in the original string. The function should handle empty strings and strings with all unique characters. The input will contain only lowercase English letters (a-z).

Constraints

0 <= len(s) <= 1000. The input contains only lowercase letters 'a' to 'z'.

Example

>>> remove_duplicate_letters("banana")
'ban'
>>> remove_duplicate_letters("hello")
'helo'
>>> remove_duplicate_letters("")
''
>>> remove_duplicate_letters("abcabc")
'abc'
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Think about using a set to track characters that have already been seen.
Iterate through the string once, appending characters that appear for the first time.
Alternatively, you can use a simple list and check membership, but a set is more efficient.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.