![]() |
VOOZH | about |
Given a string, the task is to write Java program to print all the duplicate characters with their frequency Example:
Input: str = "geeksforgeeks" Output: s : 2 e : 4 g : 2 k : 2 Input: str = "java" Output: a : 2
Approach: The idea is to do hashing using HashMap.
Below is the implementation of the above approach:
s : 2 e : 4 g : 2 k : 2
Time Complexity: O(NlogN)
Auxiliary Space: O(N) since using Map