101498A - Watching Tv
21 Nov 2020 — Tags: sorting,data-structures — URL- Maintain a map that stores the frequency count.
- Find frequency with biggest count.
Time complexity: $O(n \log(n))$
Memory complexity: $O(n)$
Click to show code.
using namespace std;
using ll = long long;
int main(void)
{
ios::sync_with_stdio(false), cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
map<int, int> counter;
while (n--)
{
string s;
int freq;
cin >> s >> freq;
counter[freq]++;
}
int ans = max_element(begin(counter), end(counter), [](auto a, auto b) {
if (a.second == b.second)
return a.first > b.first;
return a.second < b.second;
})->first;
cout << ans << endl;
}
return 0;
}