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:
abcadeecfb
Then after deleting all duplicate occurrences, the string looks like this:
abcdef
Input Format:
The only input line contains a string (STR).
Output Format:
Print the string after removing all the duplicate occurrences.
Constraints:
1 <= N <= 4*10^5
Time Limit: 1sec
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 occurr...read more
We maintain a self-balancing BST/TreeSet to keep track of all previously encountered characters.
Now, as we traverse the string, for each index, we check whether that character...read more
We can maintain a 26 sized array to keep track of whether a character has previously occurred in the string or not since it is mentioned that we will encounter only lower c...read more
public string RemoveDuplicate(string Input)
{
string output = "";
while(Input.Length !=0)
{
string firstLetter = Input.Substring(0, 1);
output = output + firstLetter;
Input = Input.Replace(fir...read more
Popular interview questions of Backend Developer
Reviews
Interviews
Salaries
Users/Month