Easy
Remove Duplicate Characters from a String
Description
In this challenge, you are required to write a function that takes a string as input and removes all duplicate characters, keeping only the first occurrence of each character.
This task is commonly used in data cleaning and processing scenarios where unique character sequences are required.
To successfully complete the task, your function should handle the following considerations:
Case Sensitivity
- The function should treat uppercase and lowercase letters as distinct characters (e.g., "A" and "a" are different).
Order Preservation
- The function should maintain the original order of characters while removing duplicates.
Example Usage
removeDuplicates("hello world"); // ➞ "helo wrd"removeDuplicates("aAaBbBcCc"); // ➞ "aAbBcC"removeDuplicates("abcabcabc"); // ➞ "abc"
Constraints
- The input will always be a valid string.
- The function should return a new string with duplicates removed.
- Empty strings should return an empty string.
Did you know?
www stands for World Wide Web.
Test Cases
Input:
"banana"
Expected Output:
"ban"
Premium Question
This question is only available to premium users.
Looking to level up your coding skills? Upgrade to Premium to access premium questions, personalized learning paths, reports, and more!