Help me where my code goes wrong

The problem code is “HEIGHTS” , its rating is 1390 and my code is:
#include <bits/stdc++.h>

using namespace std;

#define ll long long int

#define ff(i, strt, end) for(int i = strt; i < end; i++)

#define fb(i, strt, end) for(int i = strt; i >= end; i–)

#define CY cout<<“YES”<<endl;

#define CN cout<<“NO”<<endl;

void solution(){

ll n; cin>>n;

int cnt=0;

ll arr[n];

map<ll, int> mp;





for(auto &iter : mp){

    if((iter.second)==1) cnt++;


if(cnt%2==0) cout<<(cnt/2)<<endl;

else if(cnt==1) cout<<cnt<<endl;

else cout<<((cnt-1)/2)<<endl;


int main()


int t;





return 0;


Consider test case :2 2 3 3 5
actual answer :2
output by your code:1
i.e., your code fails when cnt is equal to one and the corresponding number is the highest number in the array

1 Like

thank you very much