# Help me in solving RECNDNOS problem

### My issue

plz debugging this code

### My code

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

void sort_(map<ll,ll>mp3,ll countn){
map<ll,ll>map4;
for(auto v:mp3){
map4.insert({v.second,v.first});
}

ll ans1=1002;
for(auto v:map4){
if(v.first==countn){
ans1=min(ans1,v.second);
}
else{
cout<<ans1<<endl;
return;
}
}
}

int main() {
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
vector<ll>v(n);
map<ll,ll>mp1,mp2,mp3,map4;
for(ll i=0;i<n;i++){
cin>>v[i];
}
for(ll i=0;i<n;i++){
if(v[i]=v[i+1]){
mp1[v[i]]++;
}
mp2[v[i]]++;

}
ll k=mp2.size();
ll countn=0;

for(ll i=0;i<k;i++){
ll ans=0;
ans=max(ans,(mp2[v[i]]-mp1[v[i]]));
countn=ans;
mp3[v[i]]+ans;

}

sort_(mp3,countn);
}
return 0;
}

``````

Problem Link: RECNDNOS Problem - CodeChef

@deepakjdh31
Plzz refer this solution my mine for better understanding of logic.

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int cnt=1;
map<int,int> mp;
for(int i=1;i<n;i++)
{
if(a[i]==a[i-1])
{
cnt++;
}
else
{
mp[a[i-1]]+=((cnt+1)/2);
cnt=1;
}
}
mp[a[n-1]]+=((cnt+1)/2);
int ch=INT_MAX;
int mx=0;
for(auto x:mp)
{
//cout<<x.second<<" "<<x.first<<endl;
if(x.second>mx)
{
mx=x.second;
ch=x.first;
}
else if(x.second==mx)
{
ch=min(ch,x.first);
}
}
cout<<ch<<endl;
}
return 0;
}

``````