Majority Element

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

Hello @sheikhhaji18 see the implementation 4 and 5 in this :


Happy Learning!!

okay thanks got it @tusharaggarwal272

@sheikhhaji18 you can mark this doubt as resolved.
Happy Learning!!

okay bro i will mark it and Happy New year @tusharaggarwal272

@sheikhhaji18 same to you too dear!!
Happy Learning!!

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.