Remove Duplicates From String
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
CodingNinjas
author
2y
I used a dictionary in python to count the occurrences of each letter in the word. I then used the keys of this dictionary to return the answer
CodingNinjas
author
2y
Brute Force Approach
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
CodingNinjas
author
2y
Tree Set / BST Approach
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
CodingNinjas
author
2y
Unordered Map / Set Approach
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
Add answer anonymously...
Top Cisco Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app