Majority Vote | gfg potd | 03-10-24 | GFG Problem of the day

preview_player
Показать описание
Geeks for Geeks Problem of the Day(POTD) in C++ | Majority Vote | Fully Explained🧠

Solution Code :
🌐 Connect with Me:

#GFG #POTD #geeksforgeeks #problemoftheday #c++
Gfg potd today
Рекомендации по теме
Комментарии
Автор

Brother u are doing great pls keep uploading like this only ❤❤❤, I am from mechanical branch and just started following your channel from past 5days learning a lot from you

kartikkaushik
Автор

that's mine

sort(nums.begin(), nums.end());

vector<int> v;
vector<int> ex={-1};
int div=(nums.size())/3;

int count=1, count1=0;

for(int i=0;i<(nums.size());i++)
{
if(nums[i]==nums[i+1])
{
count++;

}

else
{
if(count>div)
{
v.push_back(nums[i]);
count1++;
}


count=1;
}
}

if(count1==0)
return ex;
else
return v;

rajanchauhan
Автор

18:51
when count1 and count2 both =0, than you take ele1 and ele2 = 2 but according to your code it should be 5 ??? am i wrong

amitpatel