Some test cases are failing

#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
vector v(n);
for(int i=0;i<n;i++)
cin>>v[i];

int element1=v[0];
int count1=1;

int element2=0;
int count2=0;

for(int i=1;i<n;i++)
{
if(v[i]==element1)
{
count1++;
}
else if(v[i]==element2)
{
count2++;
}
else if(count1==0)
{
element1=v[i];
count1=1;
}
else if(count2==0)
{
element2=v[i];
count2=1;
}
else
{
count1–;
count2–;
}
}
int c1=0;
for(int i=0;i<n;i++)
{
if(v[i]==element1)
{
c1++;
}
}

int c2=0;
for(int i=0;i<n;i++)
{
if(v[i]==element2)
{
c2++;
}
}

if(c1>(n/3))
cout<<element1<<" “;
if(c2>(n/3))
cout<<element2<<” ";
if((c1<n/3)&&(c2<n/3))
cout<<“NO MAJORITY ELEMENTS”<<endl;

return 0;
}

Please send your code in a cb ide. And share the question’s hackerblocks link as well.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.