Majority Element I | Brute-Better-Optimal | Moore's Voting Algorithm | Intuition 🔥|Brute to Optimal

  Рет қаралды 220,986

take U forward

Жыл бұрын

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

Пікірлер: 515
@takeUforward
@takeUforward 10 ай бұрын
Please watch our new video on the same topic: kzfaq.info/get/bejne/rN2KnZR8lcudhWw.html
@suchitakulkarni2744
@suchitakulkarni2744 28 күн бұрын
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
@pallavi22222 10 күн бұрын
@@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.
@ShreyasinghIITPATNA
@ShreyasinghIITPATNA 2 күн бұрын
int majorityElement(vector v) { int n=v.size(); sort(v.begin(),v.end()); return v[n/2]; } this is also accepted and time complexity is O(nlogn) space is O(1)
@aamirarshad4536
@aamirarshad4536 Жыл бұрын
one leetcode a day keeps unemployment away
@shubhamkumar-hx1fb
@shubhamkumar-hx1fb 6 ай бұрын
Bro... don't ever say this 🤐
@jaswanthreddy7135
@jaswanthreddy7135 5 ай бұрын
Really?
@barnam_das
@barnam_das 4 ай бұрын
wah arshad wah
@utkarshrai101cartoonwala
@utkarshrai101cartoonwala 2 ай бұрын
Reality is often disappointing.
@rishabhranjan5162
@rishabhranjan5162 23 күн бұрын
not even the bare minimum to get a job bro
@factsmadeiteasy9943
@factsmadeiteasy9943 Жыл бұрын
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.❤❤
@takeUforward
@takeUforward Жыл бұрын
Let's march ahead, and create an unmatchable DSA course! ❤ Use the problem links in the description.
@harshavardhan184
@harshavardhan184 Жыл бұрын
Hatsoff to this consistency
@ashokasamrat8375
@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
@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
@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
@DeepakLalchandaniProfile 9 ай бұрын
Wow hats off ❤❤❤🎉
@bhubeshsr6281
@bhubeshsr6281 Жыл бұрын
Striver Bhai Level of Dedication and hardwork u put on this is .....
@cinime
@cinime Жыл бұрын
Understood! Super fantastic explanation as always, thank you so much for your effort!!
@vaibhav1247
@vaibhav1247 17 сағат бұрын
better : sorting O(nlogn) int majorityElement(vector& nums) { int n= nums.size(); sort (nums.begin(),nums.end()); return (nums[n/2]); } optimal is the same : moore's
@Surya1prakash
@Surya1prakash Жыл бұрын
Understood! Bhai never gone through such type of explanation ....thank you very much....
@habeeblaimusa4466
@habeeblaimusa4466 Жыл бұрын
Consistency 🔥 🔥. Thanks for all you do. I really appreciate
@Rohan-ce1sy
@Rohan-ce1sy 9 ай бұрын
Very good explanation. Better than any paid DSA course in market. Thank you so much Striver bhai.
@ashishbm3565
@ashishbm3565 8 ай бұрын
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!!!
@DevashishJose
@DevashishJose Жыл бұрын
Understood, Thank for explaining it so beautifully.
@musicalcasio5146
@musicalcasio5146 9 ай бұрын
huge respect for you no words 💖
@lisachakraborty528
@lisachakraborty528 5 ай бұрын
u make me fall in love with coding there was a tym i hated it i started late but yes you are true inspiration
@user-hp9kj8qt1h
@user-hp9kj8qt1h 9 сағат бұрын
I'm hating it now. Not able to build intuition myself. Always dependent on video solutions. Sometimes I feel I'm too dumb and not built for this thing. What should I do 😭😭
@yasiromar5117
@yasiromar5117 5 ай бұрын
Loved the way you explained brother. You're a true magic man
@merlingrace6850
@merlingrace6850 8 ай бұрын
Thank you for such in-depth explanation and course❣
@ArcGaming07YT
@ArcGaming07YT Жыл бұрын
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
@ahtesham4003 Жыл бұрын
👏👏
@anmolprasad6813
@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
@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
@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
@zooomba62 9 ай бұрын
i dont know why but you really helped me😊😊
@ashokasamrat8375
@ashokasamrat8375 Жыл бұрын
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.
@346_PrachiRaut
@346_PrachiRaut 3 ай бұрын
"sitting in an interview u cannot invent the algorithm" LMAOOOO xd
@akashgite905
@akashgite905 4 күн бұрын
tell them brute force then 🙂
@mahakdashore8264
@mahakdashore8264 8 ай бұрын
what a WONDERFULL EXPLANATION sir,understood every thing,please keep making these kinds of videos for us sir, please
@rishabh1S
@rishabh1S 11 ай бұрын
Understood! Moore's Voting Algorithm is Awesome.
@dhruvrawatt9
@dhruvrawatt9 Жыл бұрын
Looking forward more such videos from you bhaiya , you are awesome.
@hari7939
@hari7939 Жыл бұрын
Just no words to thank you 🙏🙏🙏
@manan-543
@manan-543 10 ай бұрын
Understood. Your explanation is amazing.
@pratikgupta7373
@pratikgupta7373 Жыл бұрын
wow really good and interactive lecture
@shesparks64
@shesparks64 9 ай бұрын
Thanks for making concept soo simple to understand :)
@reki7247
@reki7247 Жыл бұрын
wonderful way of teaching!!! Understood!
@Code_eat_sleep
@Code_eat_sleep Жыл бұрын
Understood . Thank you so much bhaiya for such a clear explanation.
@KunalSENPAI
@KunalSENPAI Жыл бұрын
Awesome explanation as always!!
@twinklelight9829
@twinklelight9829 Жыл бұрын
thankyou striver!!!! we appreciate your work☺☺
@mariselvamdheivasigamani578
@mariselvamdheivasigamani578 Жыл бұрын
Understood. Awesome explanation
@m.nirupreddy8001
@m.nirupreddy8001 Жыл бұрын
understood! great explanation🔥
@sajeethabegum4740
@sajeethabegum4740 4 ай бұрын
Very good explanation. Easy to understand. Thanks for posting this video. Hats off to your dedication.
@shadowslayer2248
@shadowslayer2248 Ай бұрын
Understood and practiced the code as always! Let's really Take Ourselves Forward!!
@user-or5oz1pk2x
@user-or5oz1pk2x 9 ай бұрын
Thank You Striver Bhaiya for Such a Quality Content...
@sukhpreetsingh5200
@sukhpreetsingh5200 Жыл бұрын
As usual amazing❤
@Nithishkumar-bx9jf
@Nithishkumar-bx9jf 3 ай бұрын
Understood! Really enjoyed your DSA lecture series ❤
@shitalpashankar3117
@shitalpashankar3117 10 ай бұрын
Love the way u teach, wonderful... thnks
@radheshpandey4659
@radheshpandey4659 11 ай бұрын
@takeUforward, Bhayia this course is really awesome.💯
@ishitaagrawal2779
@ishitaagrawal2779 Жыл бұрын
Understood!! Thanks a ton sir!!
@theprogamer3924
@theprogamer3924 6 ай бұрын
nicely explained. even though I slept while watching the video, I woke up again and understood the solution xD thanks
@ruchirtd1
@ruchirtd1 Жыл бұрын
Understood...Thanks a lot!!
@user-pc2pn6yo8r
@user-pc2pn6yo8r 6 ай бұрын
Understood bro, your explanation is top notch..
@ashmitkaur2587
@ashmitkaur2587 Жыл бұрын
Amazing explanation .
@infernogamer52
@infernogamer52 Жыл бұрын
Understood bhaiya ! Thanks a lot
@sarangkumarsingh7901
@sarangkumarsingh7901 3 ай бұрын
Understood Sir.............Awesome lec.......
@sunilkamat8199
@sunilkamat8199 Жыл бұрын
Superb Explanation 😍
@KrishnaSagar02
@KrishnaSagar02 7 ай бұрын
Understood very well brother.
@deepalivarshney23
@deepalivarshney23 Күн бұрын
literally you are amazing .
@shyam.upadhyay
@shyam.upadhyay 7 ай бұрын
Awesome content bro, love you!
@kingbadshah452
@kingbadshah452 5 ай бұрын
thanks striver understood everything
@VarunKaushal-zx9zq
@VarunKaushal-zx9zq Жыл бұрын
Understood, thank you so much
@prathameshjadhav2942
@prathameshjadhav2942 5 ай бұрын
Thank you bro i got it
@ziyadauti3676
@ziyadauti3676 9 ай бұрын
Understood ! thanks a lot sir...
@ayushbhowate42
@ayushbhowate42 Ай бұрын
understood bro , superb explanation
@berserker556
@berserker556 2 ай бұрын
Very well explained
@yashagarwal7042
@yashagarwal7042 Ай бұрын
Very Great Explanation
@Engineer-fo1dl
@Engineer-fo1dl 5 ай бұрын
Understood Clearly ❤
@ParasSharma-mf8or
@ParasSharma-mf8or Жыл бұрын
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)
@user-ym1nv1pw8i
@user-ym1nv1pw8i 23 күн бұрын
completed and understood!
@konankikeerthi
@konankikeerthi Ай бұрын
Understood bro. Thank you for your efforts
@Manishgupta200
@Manishgupta200 Жыл бұрын
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 🔥.
@Nishantkumar-oh9th
@Nishantkumar-oh9th Жыл бұрын
What an explanation man
@shubhamlipane8634
@shubhamlipane8634 11 ай бұрын
Understood Thank You :-)
@Hipfire786
@Hipfire786 2 ай бұрын
understood everything sir awesome video
@ishasinghal3457
@ishasinghal3457 7 ай бұрын
Best explanation ever❤❤
@beinginnit
@beinginnit Жыл бұрын
Loved it Striver💖💖
@ashishsharma5818
@ashishsharma5818 10 ай бұрын
great explanation of moore voting algo..
@secretcoder7
@secretcoder7 Жыл бұрын
GREAT man on this earth
@GuruPrasadShukla
@GuruPrasadShukla Жыл бұрын
just fabulous!
@riyadhossain1706
@riyadhossain1706 Жыл бұрын
I really appreciate your hard work, bhaiya. Love from the core of my heart from Bangladesh 💝💝
@NazeerBashaShaik
@NazeerBashaShaik 3 ай бұрын
Understood, thank you.
@charan123rams3
@charan123rams3 Жыл бұрын
Thank you so much sir 🙏🙏🙏
@devipavanlankalapalli7587
@devipavanlankalapalli7587 6 ай бұрын
Understood and thanks for the video
@tamilmukbang3789
@tamilmukbang3789 2 ай бұрын
understood. thank you bro
@aurobindsahu4355
@aurobindsahu4355 Жыл бұрын
Understood &&&&&& Love from odisha bhaiya
@Diptanjank
@Diptanjank 8 ай бұрын
Great Understood
@samuelfrank1369
@samuelfrank1369 8 ай бұрын
Understood. Thanks a lot . Please make more videos
@_CodeLifeChronicles_
@_CodeLifeChronicles_ Ай бұрын
oh my god the best course ever
@mayankmudgal1728
@mayankmudgal1728 9 ай бұрын
Nice video man! keep it up
@praveentiwari629
@praveentiwari629 9 ай бұрын
its crystal Clear !!!!
@supriyamanna715
@supriyamanna715 Жыл бұрын
Buk e amar gorom rokto, amra striver er vokto! great content!
@rickk3300
@rickk3300 4 ай бұрын
Nice one 😂👌
@reddygopichand2002
@reddygopichand2002 8 ай бұрын
Understood thanks 🙏
@shambhojaybhaye2822
@shambhojaybhaye2822 7 ай бұрын
very good feeling confident
@UserUser-tn8tv
@UserUser-tn8tv Жыл бұрын
Thank u so much for everything
@12_ankitaarya86
@12_ankitaarya86 11 ай бұрын
great hard work bhaiya❤❤
@AryanGairola-th3qc
@AryanGairola-th3qc 3 ай бұрын
great job brother
@amitrawat8879
@amitrawat8879 Жыл бұрын
UNDERSTOOD !!
@MandapatiGoutham
@MandapatiGoutham 2 күн бұрын
Great lecture😇
@fallenAngel-cw9ki
@fallenAngel-cw9ki Жыл бұрын
understood, ty!!
@AbhishekKumar-cv1dh
@AbhishekKumar-cv1dh Жыл бұрын
Understood 🔥!!!
@ahssanakhtar5746
@ahssanakhtar5746 Ай бұрын
Awsome content ❤‍🔥
@shibajisahu3104
@shibajisahu3104 Жыл бұрын
understood 💯💯💯💯 Dedication🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@shashankshekharshukla5743
@shashankshekharshukla5743 Жыл бұрын
Thankyou bhaiya may God bless you always. Love you 💗 striver
@itsabhinav04
@itsabhinav04 Жыл бұрын
Understood, thanks :)
@coolraviraj24
@coolraviraj24 Жыл бұрын
understood 👌
@himadriroy7980
@himadriroy7980 8 ай бұрын
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. ❤️❤️
@jagadeeshneeluri8754
@jagadeeshneeluri8754 11 ай бұрын
Understood well
@alishashaikh3859
@alishashaikh3859 10 ай бұрын
thank you so much sir
@chitikireddykusuma3287
@chitikireddykusuma3287 10 ай бұрын
For n/k times how many count variables and elements need to declared ?can you please make a video of it .
🌊Насколько Глубокий Океан ? #shorts
00:42
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 4,9 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 67 МЛН