Problem title
Difficulty
Avg time to solve

Flood Fill
Moderate
30 mins
Maximum Subtree Sum
Moderate
15 mins
Find The Nearest Supporter
Easy
10 mins
Maximum Depth Of A Binary Tree
Easy
15 mins
Four Keys Keyboard
Moderate
30 mins
Walls And Gates
Easy
15 mins
Periodic String
Easy
15 mins
Regular Expression Match
Easy
10 mins
Interval List Intersection
Easy
15 mins
Find MSB In O(1)
Easy
10 mins
4

Duplicate Characters

Difficulty: EASY
Contributed By
Anish De |Level 1
Avg. time to solve
25 min
Success Rate
70%

Problem Statement

You are given a string ‘S’ of length ‘N’. You have to return all the characters in the string that are duplicated and their frequency.

Example:-
N = 5
S = ‘GEEK’

ANSWER:- The answer should be [(‘E’,2)] because ‘E’ is the only character that is duplicated and has frequency 2.
Input Format :
The first line contains a single integer ‘T’ representing the number of test cases. Then each test case follows.

The first line of every test case contains an integer ‘N’ denoting the length of the string.

The next line of every test case contains a string ‘S’ denoting the string given.
Output Format :
For each test case, return the duplicate characters in the string S and their frequency.

The output of each test case should be printed in a separate line.
Note :
You are not required to print anything, it has already been taken care of. Just implement the function.    
Constraints :
1 <= T <= 5
1 <= N <= 10^5 

Time Limit = 1 sec
Sample Input 1 :
2
5
APPLE
6
BANANA
Sample Output 1 :
P 2
A 3
N 2
Explanation for Sample Output 1 :
In the first test case, the character ‘P’ has frequency 2 and is the only duplicate character in the string.
 In the second test case, the character ‘A’ has frequency 3 and the character ‘N’ has frequency 2. 
Sample Input 2 :
1
5
AAAAA
Sample Output 2 :
A 5
Reset Code
Full screen
copy-code
Console