Majority Element (LeetCode 169) | Full solution with 4 different methods | Interview Essential

  Рет қаралды 25,005

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 91
@ruthikapamar7981
@ruthikapamar7981 9 ай бұрын
Slick & straight! Thank you for breaking the complexity.
@sheldoncooper7990
@sheldoncooper7990 Жыл бұрын
You the one of the best here on KZbin, the way you teach, the way you keep every in a structured manner is super commendable. Subscribed.
@nikoo28
@nikoo28 Жыл бұрын
thanks for the kind words
@michaelagedie9433
@michaelagedie9433 9 ай бұрын
Keep making these videos bro, the quality is Amazing!
@Rits2203
@Rits2203 Жыл бұрын
You've explained in a very simple way!!
@palanivelraju1981
@palanivelraju1981 Жыл бұрын
there's a small mistake in the dry run in moore's algo at last votes for majority 2 is 1,when majority reaches 3 the votes will be 0, so, majority will be updated in the next iteration so majority will be update as 1, please check, explanation is too good!!!
@nikoo28
@nikoo28 Жыл бұрын
the dry-run is mainly to understand the simplicity of the code. The exact working code is available in the description too. Mostly you should understand the approach and how you are solving the problem :)
@Ramu_Sriram
@Ramu_Sriram 9 ай бұрын
Bro, the quality of your content is exceptional. You deserve more subscribers. Thank you brother.
@nikoo28
@nikoo28 8 ай бұрын
I wish that too 😄
@ayushijindal4898
@ayushijindal4898 Жыл бұрын
Beautifully Explained
@negxativexd2622
@negxativexd2622 10 ай бұрын
After watching 5 videos finally understood ... kaafi acchaa explanation...loved it
@nikoo28
@nikoo28 9 ай бұрын
Thanks for liking
@hameedmulani21
@hameedmulani21 Жыл бұрын
Superb Explanation!
@nikoo28
@nikoo28 Жыл бұрын
Thank you 🙂
@tng3100
@tng3100 8 ай бұрын
the second soln was impressive,
@MythBuster28_10
@MythBuster28_10 8 ай бұрын
Glad i found your channel
@m.abrarsheikh9865
@m.abrarsheikh9865 5 ай бұрын
Next level & Awesome explaination with cutest smile. Thank you😊
@nikoo28
@nikoo28 4 ай бұрын
that is so sweet of you
@SaniyaThrisha
@SaniyaThrisha 10 ай бұрын
this was very helpful 😀 Thank you
@satyamgupta6030
@satyamgupta6030 Жыл бұрын
great solution as always. Thanks alot bhaiya please keep on making such amazing videos.
@nikoo28
@nikoo28 Жыл бұрын
So nice of you
@velocity1186
@velocity1186 4 ай бұрын
Your teaching is superb. You have a new subscriber.
@nikoo28
@nikoo28 4 ай бұрын
Thanks a lot 😊
@marcelocarvalholopes
@marcelocarvalholopes 9 ай бұрын
Thank you. Very good explanation!
@akhintheruvath
@akhintheruvath 3 ай бұрын
Thanks for this great explanation
@amanverma8258
@amanverma8258 Жыл бұрын
Thanks a lot sir ! Really helpful
@SandipKumarRoy12
@SandipKumarRoy12 Жыл бұрын
Awesome explanation 😮😮
@Hello-l3i
@Hello-l3i 4 ай бұрын
pls make a video on peak element ... your videos are so helpful!!!!
@kunalkheeva
@kunalkheeva Жыл бұрын
thank you, your dry run really helped
@LalitSingh-nd5vx
@LalitSingh-nd5vx 9 ай бұрын
better explanation than Striver .
@riddle_cicad007
@riddle_cicad007 8 ай бұрын
Great video, you explained it so well. Thanks !!
@rakeshbabu3839
@rakeshbabu3839 3 ай бұрын
Amazing exaplanation
@bhumikabansal6022
@bhumikabansal6022 Жыл бұрын
SO CLASSY AND please make the playlist of data structures important questions too
@nikoo28
@nikoo28 Жыл бұрын
playlist: kzbin.info/aero/PLFdAYMIVJQHM8Kh5i8P2lGIbJXFPBelRI
@shravyak8535
@shravyak8535 2 ай бұрын
Best explanation.
@arnavkukreti2009
@arnavkukreti2009 3 ай бұрын
great explanation
@TakshaSharma
@TakshaSharma Жыл бұрын
amazing amazing!!!!!
@mehbubrohit12
@mehbubrohit12 Жыл бұрын
Great video man! Loved this explanation, you are highly underrated. If it's possible can you do python solutions as well for future leetcode videos? Thanks again!
@nikoo28
@nikoo28 Жыл бұрын
i would advice you to focus on the problem solving method, rather than the language. Trust me...languages will come and go...get your basics right first :)
@shubhammanecr7
@shubhammanecr7 Жыл бұрын
Amazing!
@CelestialEditzHub
@CelestialEditzHub Жыл бұрын
Amazing great explanation
@ahmedbaig8543
@ahmedbaig8543 10 ай бұрын
Very Well Explained
@nikoo28
@nikoo28 10 ай бұрын
Thank you so much 🙂
@ajaykumar-yk7to
@ajaykumar-yk7to Жыл бұрын
super sir good explanation
@arnavkukreti2009
@arnavkukreti2009 Жыл бұрын
perfect teacher
@nikoo28
@nikoo28 Жыл бұрын
perfect student :)
@albingeorgekurian4396
@albingeorgekurian4396 3 ай бұрын
it's tough to get an optimized solution 😔.... but I will try to reach it on my own 😊.
@snehaaggarwal7620
@snehaaggarwal7620 2 ай бұрын
sir in moore algo we take example as 3383372150987216 then 3 is not majority according to that or how to solve that
@mdjabedansari4561
@mdjabedansari4561 26 күн бұрын
votes suhuld be initialised to 0 at start please correct that or mention that in the description
@CSstudent_1001
@CSstudent_1001 Жыл бұрын
LEGEND 🖤
@SMARTRIXDbztttmods
@SMARTRIXDbztttmods Жыл бұрын
*Sir Please Complete top 150 interview Questions First from Leetcode 🔥*
@nikoo28
@nikoo28 Жыл бұрын
there are some problems from that list that I have covered...adding new solutions every week :)
@SMARTRIXDbztttmods
@SMARTRIXDbztttmods Жыл бұрын
@@nikoo28 *Thankyou Sir Loved your teaching Very Clear & Upto the point*
@hameedmulani21
@hameedmulani21 Жыл бұрын
​@@nikoo28 thank you!
@hameedmulani21
@hameedmulani21 Жыл бұрын
You're the best👍💯
@nikoo28
@nikoo28 Жыл бұрын
You are!
@snehaaggarwal7620
@snehaaggarwal7620 2 ай бұрын
sir in optimization in sorting if we have 1234567889 then 8 is not centered how?
@AzidzogiDizo
@AzidzogiDizo Ай бұрын
I guess because the number of eights must satisfy this condition: "The majority element is the element that appears more than ⌊n / 2⌋".
@funnymoment9164
@funnymoment9164 Жыл бұрын
Thanks!
@ShayanFallah-fj4ci
@ShayanFallah-fj4ci 2 ай бұрын
🔥
@tarunbhatt5003
@tarunbhatt5003 Жыл бұрын
great video
@subee128
@subee128 10 ай бұрын
Thanks
@yash_14h
@yash_14h Жыл бұрын
Why there are only three types of numbers? In array
@nikoo28
@nikoo28 Жыл бұрын
you can have as many types.
@dineshkinibailoor340
@dineshkinibailoor340 10 ай бұрын
the voting method returns 1 for me for array {1, 2, 2, 2, 3, 3, 1 } so is that logic correct? I think after your logic, we need to check again in the array if the count of the majority element is greater than (n/2) to be considered as the majority. In my case, the majority is returned as 1 but 1 is repeated 2 times which is not greater than the expected majority which is (>3). here we can suspect 2 could be the majority but it's not because it is not repeated more than 3 times.
@nikoo28
@nikoo28 10 ай бұрын
Majority element means the element which occurs more than n/2 times. Your test case is invalid, as it does not have a majority element. What you are talking about is the element occurring maximum number of times.
@mdsalik9374
@mdsalik9374 Жыл бұрын
What if there is no majority element? How to handle that?
@nikoo28
@nikoo28 11 ай бұрын
then it will be an entirely different problem. What are you looking to find?
@abhishekchoudhary8023
@abhishekchoudhary8023 6 ай бұрын
Can we do using 2 pointer
@nikoo28
@nikoo28 6 ай бұрын
Give me a pseudo code for your approach
@enriquegrageda
@enriquegrageda 9 ай бұрын
Thanks man, good explaining, if i land a job, ill send you some money 😁
@nikoo28
@nikoo28 9 ай бұрын
haha..thanks a bunch
@mdsalik9374
@mdsalik9374 Жыл бұрын
Can we get n/3 solution as well?
@nikoo28
@nikoo28 11 ай бұрын
do you have a link to the problem?
@foodandjournieswithme8788
@foodandjournieswithme8788 7 ай бұрын
It gives error when nums=[6,5,5]
@nikoo28
@nikoo28 7 ай бұрын
What error are you getting? I tried the case again and it gives 5 as the output
@foodandjournieswithme8788
@foodandjournieswithme8788 7 ай бұрын
@@nikoo28 sir i got output as 6 in the same code
@nikoo28
@nikoo28 7 ай бұрын
@@foodandjournieswithme8788 check your test case and code again. Here is the verified output: github.com/nikoo28/java-solutions/blob/master/src/test/java/leetcode/easy/MajorityElementTest.java
@MeghnaMukesh-hd5zk
@MeghnaMukesh-hd5zk 5 ай бұрын
The mistake in the code is that the loop starts with i = 0, which causes the initial element to be counted twice. Specifically, when the loop starts, nums[0] is already assigned to the majority and the vote is set to 1. The loop then starts from i = 0, incrementing votes for the same element. The correct approach is to start the loop from i = 1. for (int i = 1; i < nums.length; i++)
@abhiguptamusic
@abhiguptamusic Жыл бұрын
Wrong Code (Wrong understanding of mine)
@nikoo28
@nikoo28 Жыл бұрын
What part do you think is wrong?
@abhiguptamusic
@abhiguptamusic Жыл бұрын
@@nikoo28 first condition vote==0
@nikoo28
@nikoo28 Жыл бұрын
@@abhiguptamusic That condition is absolutely correct, whenever votes become =0 you need to update your majority candidate, and then increase the vote count. What error do you see in the condition? Did you try running the code?
@abhiguptamusic
@abhiguptamusic Жыл бұрын
@@nikoo28 the code is not working with another test cases
@abhiguptamusic
@abhiguptamusic Жыл бұрын
@@nikoo28 please try with these test case [1,1,2,3,4]
Majority Element - Leetcode 169 - Python
14:39
NeetCode
Рет қаралды 110 М.
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 12 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 3 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 92 МЛН
Majority Element II | Brute-Better-Optimal
26:58
take U forward
Рет қаралды 199 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 577 М.
Best Books for Learning Data Structures and Algorithms
14:01
Engineering with Utsav
Рет қаралды 374 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 245 М.
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 12 МЛН