Learner Level
Implement the removeDuplicateCharacters method that returns the text after keeping only the first occurrence of each character.
The input contains a string text. Your task is to remove duplicate characters while keeping the first occurrence of each character.
The original order of the remaining characters must be preserved. For example, banana becomes ban because b, a, and n are kept only the first time they appear.
Use a set to remember which characters are already added to the result.
Scan the string from left to right. If a character has not been seen before, append it to the result and mark it as seen. If it is already seen, skip it.
Pseudocode:
function removeDuplicateCharacters(text):
seen = empty set
result = empty string
for each character in text:
if character not in seen:
add character to result
add character to seen
return result