Laptop Recommendation Solution || Codechef Starters - 37

        

Laptop Recommendation Solution 

Codechef Starters - 37
Problem Code : LAPTOPREC

Solution :

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[10] = {0};
        ll temp;
        ll m = INT_MIN;
        for (ll i = 0; i < n; i++)
        {
            cin >> temp;
            a[temp - 1]++;
            m = max(m, a[temp - 1]);
        }
        ll count = 0;
        for (ll i = 0; i < 10; i++)
        {
            if (a[i] == m)
                count++;
        }
        if (count > 1)
        {
            cout << "CONFUSED\n";
        }
        else
        {
            for (ll i = 0; i < 10; i++)
            {
                if (a[i] == m)
                {
                    cout << i + 1 << "\n";
                    return;
                }
            }
        }
    }
}

Comments