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.

AnswerBot
4mo
Find the second most repeated word in an array of strings with unique frequencies.
Iterate through the array and count the frequency of each word using a hashmap.
Sort the hashmap by frequency in descen...read more
Help your peers!
Add answer anonymously...
Visa Fullstack Developer Intern interview questions & answers
A Fullstack Developer Intern was asked Q. Four Keys Keyboard Problem Statement Imagine you have a special keyboard with fo...read more
A Fullstack Developer Intern was asked Q. Second Most Repeated Word Problem Statement You are given an array of strings AR...read more
A Fullstack Developer Intern was asked Q. Graph Connectivity Queries Problem Given a graph with N nodes and a threshold va...read more
Popular interview questions of Fullstack Developer Intern
A Fullstack Developer Intern was asked Q1. Four Keys Keyboard Problem Statement Imagine you have a special keyboard with fo...read more
A Fullstack Developer Intern was asked Q2. Second Most Repeated Word Problem Statement You are given an array of strings AR...read more
A Fullstack Developer Intern was asked Q3. Graph Connectivity Queries Problem Given a graph with N nodes and a threshold va...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

