Aloyna is a can lover girl and whenever she goes to a shop, she must buy a can to drink. This time s…

Click here to read the complete problem statement.

If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

int n, k;
cin >> n >> k;
int ara[n+1] = {0};
int num;
for (int i = 0; i < n; i++)
{
cin >> num;
ara[num]++;
}
///sort(ara, ara + n);
int save;
int value = -1;
for (int i = 1; i <=n; i++)
if (ara[i] > value)
{
save = i;
value = ara[i];
}
// for(int i=1;i<=n;i++)
// cout<<ara[i]<<" ";
cout << save << endl;

i think this solution should work… i’m using for loop till (n) …but i initialized the whole array with 0…when i made it to go for 1 to k it works …but my question is why this Sol didt work when i went for 1 to n…?
yes there is only k values exist but i made the whole array to 0 ,when i will compare max(ara[i],value) it will cover up the logic …i’m not getting why this is not working!

a,x=map(int,input().split())
c=list(input().split())
c=sorted(c)
c=''.join(map(str,c))
b=0
for i in range(x+1):
x=c.count(str(i))
if c.count(str(i))>b:b=x;d=i
print(d)