Find Duplicate Characters in a String

Given a string with repeated characters, our task is to print characters which are occurring more than one time in a string.

For example: 
Input: s = "pythonissoeasy"
output: "s" "o" "y"

To find duplicates in a string, we need to count the occurrence of each character in a string. If count is greater than 1 then simply print that character.

The Native Method to solve this problem is using two nested for loops which take O(N^2) time to perform. But to solve this problem efficiently we can use Hashmap or Dictionary. Think about it!


Thank you so much for reading this article, if you like this question please share this with your friends who love programming. And if you have questions or feedback please drop a comment.

To solve more problems, please check out this article "Top 10 String Interview Questions".

All the Best!

Comments

Popular posts from this blog

Four Sum Problem (4sum) Solution in Java, Python, C++

Find the length of the longest substring without repeating character

Reverse Words in a Sentence Without using any Library