Majority Element I | Brute-Better-Optimal | Moore's Voting Algorithm | Intuition 🔥|Brute to Optimal
Problem Link: bit.ly/3GmPYTH
Notes/C++/Java/Python codes: takeuforward.org/data-structure/find-the-majority-element-that-occurs-more-than-n-2-times/
We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
Full Course: bit.ly/tufA2ZYt
You can follow me across social media, all my handles are below:
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
0:00 Introduction of Course
0:43 Problem Statement
1:45 Brute Force Solution
2:58 Better Solution
4:46 Code (Better Solution)
6:58 Optimal ( Moore's Voting Algorithm )
7:38 Dry run + Intuition
14:37 Code
16:52 Time complexity
17:36 Outro
Пікірлер: 504
Please watch our new video on the same topic: kzread.info/dash/bejne/qKuOzJOEYMifhZs.html
@suchitakulkarni2744
24 күн бұрын
Bhai have a doubt .. after the loop if we check cnt is not equal to 0 and return el then also the program executes properly then why we are again taking second loop ..?
@pallavi22222
6 күн бұрын
@@suchitakulkarni2744 The first loop will only give you the majority element, the second loop is used to check whether the frequency of the element from the first loop is greater than n/2. You can clearly understand this by watching once again the video from 13.00 where raj bhai explains by changing the last 4 elements to 1.
one leetcode a day keeps unemployment away
@shubhamkumar-hx1fb
6 ай бұрын
Bro... don't ever say this 🤐
@jaswanthreddy7135
4 ай бұрын
Really?
@barnam_das
3 ай бұрын
wah arshad wah
@utkarshrai101cartoonwala
2 ай бұрын
Reality is often disappointing.
@rishabhranjan5162
20 күн бұрын
not even the bare minimum to get a job bro
No matters how hard the paid courses gang will try to defame you or stop you , we STUDENTS will never stop promoting you among our friends and support you in your journey.❤❤
Let's march ahead, and create an unmatchable DSA course! ❤ Use the problem links in the description.
@harshavardhan184
Жыл бұрын
Hatsoff to this consistency
@ashokasamrat8375
Жыл бұрын
Time Stamp 0:43 - Problem Statement 1:45 - Brute Force Solution 2:58 - Better Solution 4:46 - Code (Better Solution) 6:58 - Optimal (Moore's Voting Algorithm) 7:38 - Dry run + Intuition 14:37 - Code 16:52 - Time complexity 17:36 - Outro
@umakantbhosale4718
Жыл бұрын
Hey Striver bro , It will be humble request from myside that could you please explain the approaches in Hindi&English language if possible. It will be very useful for many of students like me.
@utsavseth6573
Жыл бұрын
You dont have to ask for likes RAJ. You will get them even if you dont say. THis level of top notch content will not go un-noticed.
@DeepakLalchandaniProfile
9 ай бұрын
Wow hats off ❤❤❤🎉
Striver Bhai Level of Dedication and hardwork u put on this is .....
u make me fall in love with coding there was a tym i hated it i started late but yes you are true inspiration
Understood! Super fantastic explanation as always, thank you so much for your effort!!
very great intutions bhaiyaa!!! you are a legend. never thought i would be enjoying dsa and leetcode like this... i dont care i get a job or not but i have to finish this just for the thrill!!!
Let me help u guys understand : point 1 : moores law gives ans when there is strictly majority element present in the array. point 2 : use this example to understand it in clear way [1,2,1,3,1,4,1,5,1] if last last number was not 1 then it clearly means that there is no majority element in array else its 100% that it will be the last element in above example point 3 : understand it more by seeing these examples [1,2,3,4] gives ans as 4 but its not valid array as (there is no majority element in it) point 4 : there is no chance that we will get any other number other than majority number as ans,if there is strictly majority number present in the array and if the array is not only the valid array i,e(there is no majority element in it) then ans can be any value.
@ahtesham4003
Жыл бұрын
👏👏
@anmolprasad6813
Жыл бұрын
Thanks bro, I was so confused on this point (We could get 1 as the ans despite it not being majority) but your comment cleared it
@AffairWithGeo
11 ай бұрын
So this is valid if there is strictly a majority, else not possible? [2 2 2 1 1 1 3 3] as per the video logic 3 comes as majority. But N/2 = 8/2 = 4 to be an answer, answer has to satisfy, answer > 4. So seems like no way to . . . .??? Plz help to make things clear
@aryanpinto5105
10 ай бұрын
@@AffairWithGeo The question does mention that there does exist a majority element. Your test case itself is invalid becoz it doesn't have any majority element.
@zooomba62
9 ай бұрын
i dont know why but you really helped me😊😊
huge respect for you no words 💖
Understood! Bhai never gone through such type of explanation ....thank you very much....
Very good explanation. Better than any paid DSA course in market. Thank you so much Striver bhai.
Consistency 🔥 🔥. Thanks for all you do. I really appreciate
Loved the way you explained brother. You're a true magic man
Understood, Thank for explaining it so beautifully.
Understood and practiced the code as always! Let's really Take Ourselves Forward!!
Understood! Very well.None of them can match your dedication and energy.🔥🔥🔥🔥 And when you explain how algorithm is working the first thing comes in my mind damm! Yarr ye to kisi ne bataya hi nahi tha how the cnt is working.
"sitting in an interview u cannot invent the algorithm" LMAOOOO xd
@akashgite905
19 сағат бұрын
tell them brute force then 🙂
Thank you for such in-depth explanation and course❣
what a WONDERFULL EXPLANATION sir,understood every thing,please keep making these kinds of videos for us sir, please
Looking forward more such videos from you bhaiya , you are awesome.
Very good explanation. Easy to understand. Thanks for posting this video. Hats off to your dedication.
Just no words to thank you 🙏🙏🙏
Thanks for making concept soo simple to understand :)
Understood. Your explanation is amazing.
Understood . Thank you so much bhaiya for such a clear explanation.
Understood! Moore's Voting Algorithm is Awesome.
Thank You Striver Bhaiya for Such a Quality Content...
Understood! Really enjoyed your DSA lecture series ❤
wow really good and interactive lecture
understood! great explanation🔥
thankyou striver!!!! we appreciate your work☺☺
wonderful way of teaching!!! Understood!
Understood. Awesome explanation
Awesome explanation as always!!
Awesome content bro, love you!
As usual amazing❤
@takeUforward, Bhayia this course is really awesome.💯
nicely explained. even though I slept while watching the video, I woke up again and understood the solution xD thanks
Understood bro. Thank you for your efforts
Understood bro, your explanation is top notch..
Super Duper Amazing... Your explaination from brute-better-optimal is fantastic with Time and Space complexity. Moor's Voting Algorithm explained by you is really awesome without using any extra space. The best thing like once in a blue moon type.. I liked the most is you explain in a unique way in every tutorial.. Here is.. like.. How Time complexity is O(N) not added (because in problem, array have atleast one majority element. So, here TC < O(N) always at the time of checking majority) in Moore's Voting algorithm at the time of checking 'el' is majourity or not.. And also you explain Space Complexity also. Thankyou Striver for such an amazing tutorial 🔥.
Understood!! Thanks a ton sir!!
Understood...Thanks a lot!!
Understood very well brother.
Understood bhaiya ! Thanks a lot
Thank you bro i got it
Understood. Thanks a lot . Please make more videos
Understood Clearly ❤
Understood ! thanks a lot sir...
Oh God dimag hil Gaya pura. How did someone invent so innovative algorithms and how can someone explain it so lucidly. Striver daa you are just CODING GOD. Uff 🔥🔥🔥. May God bless you always. ❤️❤️
Nice video man! keep it up
Love the way u teach, wonderful... thnks
oh my god the best course ever
completed and understood!
Understood, thank you so much
Understood Sir.............Awesome lec.......
thanks striver understood everything
Amazing explanation .
Hi Raj, Thanks for the video. As per your explanation, one more slight optimisation we can do in Moore's Voting Algorithm if we're not sure whether majority element exists. Say we have array size n and n%2==0(means and even size array) and if our count value at last is also 0 in that case we do not need to go to the 2nd step i.e. traverse the whole array again to get the occurrence of element(ele variable value). Hope it makes sense.
Very Great Explanation
Superb Explanation 😍
understood bro , superb explanation
Understood, thank you.
great explanation of moore voting algo..
understood everything sir awesome video
I really appreciate your hard work, bhaiya. Love from the core of my heart from Bangladesh 💝💝
Very well explained
Understood 🔥!!!
understood. thank you bro
Loved it Striver💖💖
What an explanation man
0:00 Introduction of course 0:46 Majority Element(>n/2) 1:48 Brute approach 2:17 Pseudo code (Brute) 2:56 Better solution 4:45 Code-compiler (Better solution) 6:59 Optimal(Moore's Voting Algorithm) 7:56 Algorithm explanation+Dry run 14:37 Code-compiler (Optimal approach)
just fabulous!
Understood Thank You :-)
GREAT man on this earth
great hard work bhaiya❤❤
UNDERSTOOD !!
its crystal Clear !!!!
Understood and thanks for the video
Understood &&&&&& Love from odisha bhaiya
Best explanation ever❤❤
Great Understood
very good feeling confident
Awsome content ❤🔥
Thank you so much sir 🙏🙏🙏
great job brother
Understood! ❤
Understood, thanks :)
Understood thanks 🙏
Thankyou bhaiya may God bless you always. Love you 💗 striver
Understood!!❤
understood, ty!!
Thank u so much for everything
Understood ❤️
understood 💯💯💯💯 Dedication🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
understood 👌
Understood!
Understood bruh.❤🔥
Understood 😊