Remove duplicate characters
Coding problemEasyAsked in: Cognizant, Infosys, Wipro
Given a string s, return it with every repeated character removed. Keep the first occurrence of each character and keep the original order.
Spaces are characters too, so only the first space is kept. Upper and lower case are different characters.
Examples
Example 1
Input: s = "programming"
Output: "progamin"
Example 2
Input: s = "aabbcc"
Output: "abc"
Example 3
Input: s = "a b c"
Output: "a bc"
The second space is a repeat, so it goes.
Constraints
- The length of s is between 0 and 100,000
- s holds printable ASCII characters only
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.