Second Most Repeated Word Problem Statement
You are given an array of strings ARR
. The task is to find out the second most frequently repeated word in the array. It is guaranteed that each string in the array has a unique frequency of occurrence. If there is only one unique string in the array, return an empty string.
Example:
Input:
N = 5
S = ['aaa', 'bbb', 'ccc', 'aaa', 'bbb', 'aaa']
Output:
'bbb'
Explanation:
The word 'aaa' is repeated 3 times and 'bbb' is repeated 2 times. Thus, 'bbb' is the second most repeated word in the array.
Constraints:
1 <= T <= 10
1 <= N <= 1000
1 <= |ARR[i]| <= 1000
- It is guaranteed that every string has a unique frequency in the array.
Input:
The first line contains a single integer ‘T’ representing the number of test cases. Each test case follows: The first line contains an integer ‘N’ denoting the length of the array. The next line contains ‘N’ strings denoting the elements of the array.
Output:
For each test case, return the second most repeated word in the array. If there is only one unique string in the array, return an empty string. The output for each test case should be printed on a separate line.
Note:
You are not required to print anything; just implement the function to return the correct result.
Be the first one to answer
Add answer anonymously...
Top Visa Fullstack Developer Intern interview questions & answers
Popular interview questions of Fullstack 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