Skip to content

Commit 227e6d1

Browse files
committed
Added solution - LeetHub
1 parent 1311520 commit 227e6d1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//{ Driver Code Starts
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
// } Driver Code Ends
6+
7+
class Solution
8+
{
9+
public:
10+
string secFrequent (string arr[], int n)
11+
{
12+
map<string,int>m;
13+
for(int i=0;i<n;i++){
14+
m[arr[i]]++;
15+
}
16+
if(m.size()<2){
17+
return "";
18+
}
19+
map<int,string,greater<int>>m2;
20+
for(auto i:m){
21+
m2[i.second]=i.first;
22+
}
23+
return (++m2.begin())->second;
24+
}
25+
};
26+
27+
//{ Driver Code Starts.
28+
int main()
29+
{
30+
int t; cin >> t;
31+
while (t--)
32+
{
33+
int n; cin >> n;
34+
string arr[n];
35+
for (int i = 0; i < n; ++i)
36+
cin >> arr[i];
37+
Solution ob;
38+
cout << ob.secFrequent (arr, n) << endl;
39+
}
40+
}
41+
// Contributed By: Pranay Bansal
42+
43+
// } Driver Code Ends

0 commit comments

Comments
 (0)