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

  • @takeUforward
    @takeUforward10 ай бұрын

    Please watch our new video on the same topic: kzread.info/dash/bejne/qKuOzJOEYMifhZs.html

  • @suchitakulkarni2744

    @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

    @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.

  • @aamirarshad4536
    @aamirarshad4536 Жыл бұрын

    one leetcode a day keeps unemployment away

  • @shubhamkumar-hx1fb

    @shubhamkumar-hx1fb

    6 ай бұрын

    Bro... don't ever say this 🤐

  • @jaswanthreddy7135

    @jaswanthreddy7135

    4 ай бұрын

    Really?

  • @barnam_das

    @barnam_das

    3 ай бұрын

    wah arshad wah

  • @utkarshrai101cartoonwala

    @utkarshrai101cartoonwala

    2 ай бұрын

    Reality is often disappointing.

  • @rishabhranjan5162

    @rishabhranjan5162

    20 күн бұрын

    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 .....

  • @lisachakraborty528
    @lisachakraborty5285 ай бұрын

    u make me fall in love with coding there was a tym i hated it i started late but yes you are true inspiration

  • @cinime
    @cinime Жыл бұрын

    Understood! Super fantastic explanation as always, thank you so much for your effort!!

  • @ashishbm3565
    @ashishbm35658 ай бұрын

    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!!!

  • @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😊😊

  • @musicalcasio5146
    @musicalcasio51469 ай бұрын

    huge respect for you no words 💖

  • @Surya1prakash
    @Surya1prakash Жыл бұрын

    Understood! Bhai never gone through such type of explanation ....thank you very much....

  • @Rohan-ce1sy
    @Rohan-ce1sy9 ай бұрын

    Very good explanation. Better than any paid DSA course in market. Thank you so much Striver bhai.

  • @habeeblaimusa4466
    @habeeblaimusa4466 Жыл бұрын

    Consistency 🔥 🔥. Thanks for all you do. I really appreciate

  • @yasiromar5117
    @yasiromar51174 ай бұрын

    Loved the way you explained brother. You're a true magic man

  • @DevashishJose
    @DevashishJose Жыл бұрын

    Understood, Thank for explaining it so beautifully.

  • @shadowslayer2248
    @shadowslayer2248Ай бұрын

    Understood and practiced the code as always! Let's really Take Ourselves Forward!!

  • @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_PrachiRaut2 ай бұрын

    "sitting in an interview u cannot invent the algorithm" LMAOOOO xd

  • @akashgite905

    @akashgite905

    19 сағат бұрын

    tell them brute force then 🙂

  • @merlingrace6850
    @merlingrace68508 ай бұрын

    Thank you for such in-depth explanation and course❣

  • @mahakdashore8264
    @mahakdashore82648 ай бұрын

    what a WONDERFULL EXPLANATION sir,understood every thing,please keep making these kinds of videos for us sir, please

  • @dhruvrawatt9
    @dhruvrawatt9 Жыл бұрын

    Looking forward more such videos from you bhaiya , you are awesome.

  • @sajeethabegum4740
    @sajeethabegum47404 ай бұрын

    Very good explanation. Easy to understand. Thanks for posting this video. Hats off to your dedication.

  • @hari7939
    @hari7939 Жыл бұрын

    Just no words to thank you 🙏🙏🙏

  • @shesparks64
    @shesparks649 ай бұрын

    Thanks for making concept soo simple to understand :)

  • @manan-543
    @manan-54310 ай бұрын

    Understood. Your explanation is amazing.

  • @Code_eat_sleep
    @Code_eat_sleep Жыл бұрын

    Understood . Thank you so much bhaiya for such a clear explanation.

  • @rishabh1S
    @rishabh1S11 ай бұрын

    Understood! Moore's Voting Algorithm is Awesome.

  • @user-or5oz1pk2x
    @user-or5oz1pk2x9 ай бұрын

    Thank You Striver Bhaiya for Such a Quality Content...

  • @Nithishkumar-bx9jf
    @Nithishkumar-bx9jf3 ай бұрын

    Understood! Really enjoyed your DSA lecture series ❤

  • @pratikgupta7373
    @pratikgupta7373 Жыл бұрын

    wow really good and interactive lecture

  • @m.nirupreddy8001
    @m.nirupreddy8001 Жыл бұрын

    understood! great explanation🔥

  • @twinklelight9829
    @twinklelight9829 Жыл бұрын

    thankyou striver!!!! we appreciate your work☺☺

  • @reki7247
    @reki7247 Жыл бұрын

    wonderful way of teaching!!! Understood!

  • @mariselvamdheivasigamani578
    @mariselvamdheivasigamani578 Жыл бұрын

    Understood. Awesome explanation

  • @KunalSENPAI
    @KunalSENPAI Жыл бұрын

    Awesome explanation as always!!

  • @shyam.upadhyay
    @shyam.upadhyay7 ай бұрын

    Awesome content bro, love you!

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Жыл бұрын

    As usual amazing❤

  • @radheshpandey4659
    @radheshpandey465911 ай бұрын

    @takeUforward, Bhayia this course is really awesome.💯

  • @theprogamer3924
    @theprogamer39246 ай бұрын

    nicely explained. even though I slept while watching the video, I woke up again and understood the solution xD thanks

  • @konankikeerthi
    @konankikeerthiАй бұрын

    Understood bro. Thank you for your efforts

  • @user-pc2pn6yo8r
    @user-pc2pn6yo8r6 ай бұрын

    Understood bro, your explanation is top notch..

  • @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 🔥.

  • @ishitaagrawal2779
    @ishitaagrawal2779 Жыл бұрын

    Understood!! Thanks a ton sir!!

  • @ruchirtd1
    @ruchirtd1 Жыл бұрын

    Understood...Thanks a lot!!

  • @KrishnaSagar02
    @KrishnaSagar027 ай бұрын

    Understood very well brother.

  • @infernogamer52
    @infernogamer52 Жыл бұрын

    Understood bhaiya ! Thanks a lot

  • @prathameshjadhav2942
    @prathameshjadhav29425 ай бұрын

    Thank you bro i got it

  • @samuelfrank1369
    @samuelfrank13698 ай бұрын

    Understood. Thanks a lot . Please make more videos

  • @Engineer-fo1dl
    @Engineer-fo1dl5 ай бұрын

    Understood Clearly ❤

  • @ziyadauti3676
    @ziyadauti36769 ай бұрын

    Understood ! thanks a lot sir...

  • @himadriroy7980
    @himadriroy79807 ай бұрын

    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. ❤️❤️

  • @mayankmudgal1728
    @mayankmudgal17289 ай бұрын

    Nice video man! keep it up

  • @shitalpashankar3117
    @shitalpashankar311710 ай бұрын

    Love the way u teach, wonderful... thnks

  • @_CodeLifeChronicles_
    @_CodeLifeChronicles_Ай бұрын

    oh my god the best course ever

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i20 күн бұрын

    completed and understood!

  • @VarunKaushal-zx9zq
    @VarunKaushal-zx9zq Жыл бұрын

    Understood, thank you so much

  • @sarangkumarsingh7901
    @sarangkumarsingh79013 ай бұрын

    Understood Sir.............Awesome lec.......

  • @kingbadshah452
    @kingbadshah4525 ай бұрын

    thanks striver understood everything

  • @ashmitkaur2587
    @ashmitkaur2587 Жыл бұрын

    Amazing explanation .

  • @impalash_ag
    @impalash_agАй бұрын

    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.

  • @yashagarwal7042
    @yashagarwal7042Ай бұрын

    Very Great Explanation

  • @sunilkamat8199
    @sunilkamat8199 Жыл бұрын

    Superb Explanation 😍

  • @ayushbhowate42
    @ayushbhowate42Ай бұрын

    understood bro , superb explanation

  • @NazeerBashaShaik
    @NazeerBashaShaik3 ай бұрын

    Understood, thank you.

  • @ashishsharma5818
    @ashishsharma581810 ай бұрын

    great explanation of moore voting algo..

  • @Hipfire786
    @Hipfire7862 ай бұрын

    understood everything sir awesome video

  • @riyadhossain1706
    @riyadhossain1706 Жыл бұрын

    I really appreciate your hard work, bhaiya. Love from the core of my heart from Bangladesh 💝💝

  • @berserker556
    @berserker5562 ай бұрын

    Very well explained

  • @AbhishekKumar-cv1dh
    @AbhishekKumar-cv1dh Жыл бұрын

    Understood 🔥!!!

  • @tamilmukbang3789
    @tamilmukbang37892 ай бұрын

    understood. thank you bro

  • @beinginnit
    @beinginnit Жыл бұрын

    Loved it Striver💖💖

  • @Nishantkumar-oh9th
    @Nishantkumar-oh9th Жыл бұрын

    What an explanation man

  • @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)

  • @GuruPrasadShukla
    @GuruPrasadShukla Жыл бұрын

    just fabulous!

  • @shubhamlipane8634
    @shubhamlipane863411 ай бұрын

    Understood Thank You :-)

  • @secretcoder7
    @secretcoder7 Жыл бұрын

    GREAT man on this earth

  • @12_ankitaarya86
    @12_ankitaarya8611 ай бұрын

    great hard work bhaiya❤❤

  • @amitrawat8879
    @amitrawat8879 Жыл бұрын

    UNDERSTOOD !!

  • @praveentiwari629
    @praveentiwari6299 ай бұрын

    its crystal Clear !!!!

  • @devipavanlankalapalli7587
    @devipavanlankalapalli75876 ай бұрын

    Understood and thanks for the video

  • @aurobindsahu4355
    @aurobindsahu4355 Жыл бұрын

    Understood &&&&&& Love from odisha bhaiya

  • @ishasinghal3457
    @ishasinghal34577 ай бұрын

    Best explanation ever❤❤

  • @Diptanjank
    @Diptanjank7 ай бұрын

    Great Understood

  • @shambhojaybhaye2822
    @shambhojaybhaye28227 ай бұрын

    very good feeling confident

  • @ahssanakhtar5746
    @ahssanakhtar5746Ай бұрын

    Awsome content ❤‍🔥

  • @charan123rams3
    @charan123rams3 Жыл бұрын

    Thank you so much sir 🙏🙏🙏

  • @AryanGairola-th3qc
    @AryanGairola-th3qc3 ай бұрын

    great job brother

  • @pranayjain._
    @pranayjain._11 ай бұрын

    Understood! ❤

  • @itsabhinav04
    @itsabhinav04 Жыл бұрын

    Understood, thanks :)

  • @reddygopichand2002
    @reddygopichand20028 ай бұрын

    Understood thanks 🙏

  • @shashankshekharshukla5743
    @shashankshekharshukla5743 Жыл бұрын

    Thankyou bhaiya may God bless you always. Love you 💗 striver

  • @HARSHA_27
    @HARSHA_278 ай бұрын

    Understood!!❤

  • @fallenAngel-cw9ki
    @fallenAngel-cw9ki Жыл бұрын

    understood, ty!!

  • @UserUser-tn8tv
    @UserUser-tn8tv Жыл бұрын

    Thank u so much for everything

  • @rajatpatra2593
    @rajatpatra2593 Жыл бұрын

    Understood ❤️

  • @shibajisahu3104
    @shibajisahu3104 Жыл бұрын

    understood 💯💯💯💯 Dedication🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @coolraviraj24
    @coolraviraj24 Жыл бұрын

    understood 👌

  • @sayakghosh5104
    @sayakghosh5104 Жыл бұрын

    Understood!

  • @SelvaArumugam-xq5mf
    @SelvaArumugam-xq5mf Жыл бұрын

    Understood bruh.❤‍🔥

  • @shubhamsharma8364
    @shubhamsharma8364 Жыл бұрын

    Understood 😊

Келесі