Can someone please tell why my answer is wrong.

I am attaching both problem and my solution.

https://www.codechef.com/LTIME87B/problems/MODEFREQ

https://www.codechef.com/viewsolution/37248310

give the size of vector b as n not 11

1 Like

You made a mistake here

```
vector<ll> b(11,0);
for(ll i=1;i<=10;i++)
b[a[i]]++;
for(ll i=10;i>=1;i--)
{
if(m<=b[i])
{
m=b[i];
c=i;
}
}
```

You misunderstood something,

```
1<=N<=10^5
1<=Ai<=10
```

say suppose if you have n=10^5

and you have `n/2`

times `1`

there and `n/2`

times `2`

there.

So, your `vector <ll> a(11,0)`

will have `0 50000 50000 0 0 0 0 0 0 0 0`

correct.!?

Now when you make second `vector<ll> b(11,0)`

```
for(ll i=1;i<=10;i++)
b[a[i]]++;
```

so you look for b[50000] does it even exists? no !

Instead take a hasmap. it will work !!

Hope it would help.

1 Like

i thought i was wrong from seeing my notification

LOLL !! No !!

but making size of b as n will make it quite inefficient yet it will be accepted

1 Like

yeah i get it

1 Like

Thank you. This was really helpful.

1 Like