← All coding problems
Remove Duplicate Characters
easyPlacement Coding+10 XPTime limit 2s
Remove every repeated character from the string, keeping only the first occurrence of each one and the original order. programming becomes progamin.
Input: one line with a string of letters and digits (no spaces). Upper and lower case are different characters.
Output: the string without duplicates.
Constraints: 1 ≤ length ≤ 10⁵.
Think about it: keep a "seen" table (a boolean array of size 128, or a set). Append a character to the answer only the first time you see it.
Sample input 1
programming
Sample output 1
progamin
Sample input 2
Skills101
Sample output 2
Skils10
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).