Majority Element 2 and 1 || Intuition + Example + Code || Find elements occuring more than n/3 times

  Рет қаралды 12,338

Code with Alisha

Code with Alisha

Күн бұрын

Majority element 2 :
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.
Follow-up: Could you solve the problem in linear time and in O(1) space?
Majority element 1 )
Given an array nums of size n, return the majority element.
The majority element is the element that appears more than ⌊n / 2⌋ times.

Пікірлер: 43
@siddhantganesh
@siddhantganesh 2 жыл бұрын
The game example just flipped my mind. And it was like...now I can never forget Moore's algo. The example you used was just amazing. Thanks Alisha
@shanayagupta4002
@shanayagupta4002 Жыл бұрын
i 100% agree with u
@nishantpratyush4191
@nishantpratyush4191 2 жыл бұрын
What a mind blowing explanation di🤯.... Was struggling with this question from the last two days.... I still can't believe that I understood🥺
@none2868
@none2868 Жыл бұрын
Was struggling with this problem. Your explanation was overwhelmingly helpful!
@gedelasivakrishna
@gedelasivakrishna 8 ай бұрын
I understand easily by your explination, thankyou !!
@anonymousperson7586
@anonymousperson7586 3 ай бұрын
one of the best explanation of this approach.
@kawaljeetsingh1657
@kawaljeetsingh1657 Ай бұрын
Thank you for the explanation, Simple, Best and No Story telling like others..... Straight to the point and saved good amount of time...... No doubts, Had to subscribe.....
@durgeshkushwaha2534
@durgeshkushwaha2534 Жыл бұрын
Once again excellent explanation .thank you so much mam ❤❤ Honestly, whenever I want to find the solution to any question, I look for your video first :) And Thank you again for accepting the connection request on Linked In.
@user-vj5fq6hf4k
@user-vj5fq6hf4k 2 жыл бұрын
best explanation on moore's so far...thank you so much
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
You're very welcome!
@gokulnaathbaskar9808
@gokulnaathbaskar9808 Жыл бұрын
Love your energy while teaching, the first part of the video is very clear, thank you so much
@siddhantganesh
@siddhantganesh 2 жыл бұрын
This is one of the best explanation for majority element !!!!
@gokulnaathbaskar9808
@gokulnaathbaskar9808 Жыл бұрын
Exactly!
@jeeva3118
@jeeva3118 Ай бұрын
This Video help me to clarify my doubts..
@niteshkoli007
@niteshkoli007 2 жыл бұрын
I will never forget the concept of this question 😂, game example was the best to remember it,🙌thank you so much.
@artyCrafty4564
@artyCrafty4564 11 ай бұрын
just WOW...i am speechless...cann't describe
@utkarshasingh1836
@utkarshasingh1836 Жыл бұрын
Probably the best explanation available.
@Shubham-yc6nz
@Shubham-yc6nz Жыл бұрын
Thanks for the game example. You are awesome teacher as always.
@pratikkumarjha5995
@pratikkumarjha5995 2 жыл бұрын
Didi can we use frequency array for this question...... Amazing explanation di...
@jkengineeringworkvideos7282
@jkengineeringworkvideos7282 2 жыл бұрын
nah that wont be constant space complexity
@KS0607
@KS0607 2 жыл бұрын
I think for N/3 question the coding is wrong. both candidate 1 & candidate 2 will be same by that code u r simply applying same conditions for two variables....how can outcome will be diff?
@chandrakiran764
@chandrakiran764 Ай бұрын
thank you for intution
@lakshay6043
@lakshay6043 2 жыл бұрын
great explanation
@jatinlanje5741
@jatinlanje5741 2 жыл бұрын
this life and shoot example was really
@MONUKUMAR-li8qg
@MONUKUMAR-li8qg 2 жыл бұрын
Great Explanation.
@tarunbehera934
@tarunbehera934 Жыл бұрын
2nd for loop is for 0 winners, right?
@shivanshgupta1509
@shivanshgupta1509 2 жыл бұрын
ThanYou so much mam !!!!!
@sauravjha552
@sauravjha552 2 жыл бұрын
Nice Explaination
@mapradnardev
@mapradnardev 2 жыл бұрын
For N/2 majority element this return wrong answer for A={3,4,3,4,11} it returns 1 but it is not majority elemnt
@siddhantganesh
@siddhantganesh 2 жыл бұрын
Read the question carefully on leetcode. "The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array." The majority element always exist !
@mapradnardev
@mapradnardev 2 жыл бұрын
@@siddhantganesh i think we need to count the candidate element again to check for validity
@naveengoyal5243
@naveengoyal5243 2 жыл бұрын
@pradhan - For n/2 case, The question says "You may assume that the majority element always exists in the array", the example case (A={3,4,3,4,1,1}) you have taken for this question itself is wrong. The question says that you just have to find the majority element in the array and it will always exist in the array. While on the other hand, for n/3 case, it is never mentioned that "you can assume at least one n/3 element will exist", that's why we are counting and to know if 0 or 1 or 2 elements exists having more than n/3 count.
@vishwassahu
@vishwassahu 2 жыл бұрын
this soln won't work for [1,1,1]
@GhostRider....
@GhostRider.... 2 жыл бұрын
Which case you are asking for n/3 or n/2?
@Shubham-yc6nz
@Shubham-yc6nz Жыл бұрын
While counting add the second if in else block E.g If () cnt1++ Else if() cnt2++
@bhai-bm4kj
@bhai-bm4kj Жыл бұрын
love you didi
@ketansharma6955
@ketansharma6955 Жыл бұрын
wow!
@Idukhan-jj9kc
@Idukhan-jj9kc 3 жыл бұрын
👍👍👍👍💯
@lavanyakataria101
@lavanyakataria101 2 жыл бұрын
Do share the code
@lavanyakataria101
@lavanyakataria101 2 жыл бұрын
Di, can you make a video on how to build logic, solution seems easy by watching your videos, but getting it done by myself is tough. How to build logic like you?
@GhostRider....
@GhostRider.... 2 жыл бұрын
@@lavanyakataria101 just do questions, after doing around 200 - 300 questions your logic will start building, and also revise these questions
@inspired_enough_to_grow_up
@inspired_enough_to_grow_up 3 жыл бұрын
OS ki sheet dedo didi
@drop009
@drop009 2 жыл бұрын
you don't think you should provide links of your code . 🤔 rest the explanation was so good !
Gas Station or Circular Tour problem
21:38
Code with Alisha
Рет қаралды 13 М.
My Daughter's Dumplings Are Filled With Coins #funny #cute #comedy
00:18
Funny daughter's daily life
Рет қаралды 29 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,2 МЛН
Зу-зу Күлпаш 2. Интернет мошенник
40:13
ASTANATV Movie
Рет қаралды 582 М.
😜 #aminkavitaminka #aminokka #аминкавитаминка
00:14
Аминка Витаминка
Рет қаралды 608 М.
Majority Element II | Brute-Better-Optimal
26:58
take U forward
Рет қаралды 185 М.
Count Inversions in Array
11:48
Code with Alisha
Рет қаралды 11 М.
Majority Element II - Leetcode 229 - Python
14:34
NeetCodeIO
Рет қаралды 17 М.
Majority Element - Leetcode 169 - Python
14:39
NeetCode
Рет қаралды 105 М.
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 884 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 661 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 315 М.
Majority Element II | GOOGLE Interview Question | Brute-Better-Optimal
12:45
My Daughter's Dumplings Are Filled With Coins #funny #cute #comedy
00:18
Funny daughter's daily life
Рет қаралды 29 МЛН