question–>
https://practice.geeksforgeeks.org/problems/majority-element-1587115620/1
code–>
int majorityElement(int nums[], int size)
{
// your code here
int element=0;
int count=0;
for(int i=0;i<size;i++){
if(count==0){
element=nums[i];
}
if(element==nums[i]){
count++;
}
else{
count--;
}
}
if(count!=0){
return element;
}
return -1;
}
Not passing all testcases