Remove Duplicates From String

Posted: 27 Jul, 2020
Difficulty: Moderate


Try Problem

You are given a string (STR) of length N, consisting of only the lower case English alphabet.

Your task is to remove all the duplicate occurrences of characters in the string.

For Example:
If the given string is:

Then after deleting all duplicate occurrences, the string looks like this:
Input Format:
The only input line contains a string (STR).
Output Format:
Print the string after removing all the duplicate occurrences.
1 <= N <= 4*10^5

Time Limit: 1sec
Approach 1

Iterate for each character of the string. For each index, we run another loop starting from the beginning of the string upto that index, and check whether that character has occurred before. If so, we do not include this character in the final string.

Try Problem