Тёмный

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

Nikhil Lohia
Подписаться 49 тыс.
Просмотров 23 тыс.
50% 1

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 88   
@ruthikapamar7981
@ruthikapamar7981 8 месяцев назад
Slick & straight! Thank you for breaking the complexity.
@sheldoncooper7990
@sheldoncooper7990 Год назад
You the one of the best here on RU-vid, the way you teach, the way you keep every in a structured manner is super commendable. Subscribed.
@nikoo28
@nikoo28 11 месяцев назад
thanks for the kind words
@michaelagedie9433
@michaelagedie9433 7 месяцев назад
Keep making these videos bro, the quality is Amazing!
@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 :)
@Rits2203
@Rits2203 Год назад
You've explained in a very simple way!!
@Ramu_Sriram
@Ramu_Sriram 7 месяцев назад
Bro, the quality of your content is exceptional. You deserve more subscribers. Thank you brother.
@nikoo28
@nikoo28 6 месяцев назад
I wish that too 😄
@ayushijindal4898
@ayushijindal4898 Год назад
Beautifully Explained
@MythBuster28_10
@MythBuster28_10 6 месяцев назад
Glad i found your channel
@negxativexd2622
@negxativexd2622 9 месяцев назад
After watching 5 videos finally understood ... kaafi acchaa explanation...loved it
@nikoo28
@nikoo28 8 месяцев назад
Thanks for liking
@satyamgupta6030
@satyamgupta6030 Год назад
great solution as always. Thanks alot bhaiya please keep on making such amazing videos.
@nikoo28
@nikoo28 Год назад
So nice of you
@SaniyaThrisha
@SaniyaThrisha 8 месяцев назад
this was very helpful 😀 Thank you
@shravyak8535
@shravyak8535 Месяц назад
Best explanation.
@m.abrarsheikh9865
@m.abrarsheikh9865 3 месяца назад
Next level & Awesome explaination with cutest smile. Thank you😊
@nikoo28
@nikoo28 3 месяца назад
that is so sweet of you
@hameedmulani21
@hameedmulani21 Год назад
Superb Explanation!
@nikoo28
@nikoo28 Год назад
Thank you 🙂
@amanverma8258
@amanverma8258 Год назад
Thanks a lot sir ! Really helpful
@akhintheruvath
@akhintheruvath 2 месяца назад
Thanks for this great explanation
@velocity1186
@velocity1186 2 месяца назад
Your teaching is superb. You have a new subscriber.
@nikoo28
@nikoo28 2 месяца назад
Thanks a lot 😊
@SandipKumarRoy12
@SandipKumarRoy12 Год назад
Awesome explanation 😮😮
@arnavkukreti2009
@arnavkukreti2009 2 месяца назад
great explanation
@Hello-l3i
@Hello-l3i 2 месяца назад
pls make a video on peak element ... your videos are so helpful!!!!
@bhumikabansal6022
@bhumikabansal6022 Год назад
SO CLASSY AND please make the playlist of data structures important questions too
@nikoo28
@nikoo28 11 месяцев назад
playlist: ru-vid.com/group/PLFdAYMIVJQHM8Kh5i8P2lGIbJXFPBelRI
@kunalkheeva
@kunalkheeva Год назад
thank you, your dry run really helped
@rakeshbabu3839
@rakeshbabu3839 2 месяца назад
Amazing exaplanation
@marcelocarvalholopes
@marcelocarvalholopes 7 месяцев назад
Thank you. Very good explanation!
@riddle_cicad007
@riddle_cicad007 7 месяцев назад
Great video, you explained it so well. Thanks !!
@mehbubrohit12
@mehbubrohit12 11 месяцев назад
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 11 месяцев назад
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 :)
@tng3100
@tng3100 6 месяцев назад
the second soln was impressive,
@LalitSingh-nd5vx
@LalitSingh-nd5vx 7 месяцев назад
better explanation than Striver .
@ajaykumar-yk7to
@ajaykumar-yk7to Год назад
super sir good explanation
@shubhammanecr7
@shubhammanecr7 Год назад
Amazing!
@albingeorgekurian4396
@albingeorgekurian4396 2 месяца назад
it's tough to get an optimized solution 😔.... but I will try to reach it on my own 😊.
@TakshaSharma
@TakshaSharma Год назад
amazing amazing!!!!!
@CelestialEditzHub
@CelestialEditzHub Год назад
Amazing great explanation
@ahmedbaig8543
@ahmedbaig8543 9 месяцев назад
Very Well Explained
@nikoo28
@nikoo28 9 месяцев назад
Thank you so much 🙂
@subee128
@subee128 9 месяцев назад
Thanks
@snehaaggarwal7620
@snehaaggarwal7620 24 дня назад
sir in optimization in sorting if we have 1234567889 then 8 is not centered how?
@snehaaggarwal7620
@snehaaggarwal7620 24 дня назад
sir in moore algo we take example as 3383372150987216 then 3 is not majority according to that or how to solve that
@arnavkukreti2009
@arnavkukreti2009 Год назад
perfect teacher
@nikoo28
@nikoo28 11 месяцев назад
perfect student :)
@ShayanFallah-fj4ci
@ShayanFallah-fj4ci 15 дней назад
🔥
@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!
@yash_14h
@yash_14h Год назад
Why there are only three types of numbers? In array
@nikoo28
@nikoo28 11 месяцев назад
you can have as many types.
@CSstudent_1001
@CSstudent_1001 11 месяцев назад
LEGEND 🖤
@funnymoment9164
@funnymoment9164 11 месяцев назад
Thanks!
@tarunbhatt5003
@tarunbhatt5003 Год назад
great video
@hameedmulani21
@hameedmulani21 Год назад
You're the best👍💯
@nikoo28
@nikoo28 Год назад
You are!
@dineshkinibailoor340
@dineshkinibailoor340 8 месяцев назад
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 8 месяцев назад
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.
@enriquegrageda
@enriquegrageda 8 месяцев назад
Thanks man, good explaining, if i land a job, ill send you some money 😁
@nikoo28
@nikoo28 7 месяцев назад
haha..thanks a bunch
@abhishekchoudhary8023
@abhishekchoudhary8023 5 месяцев назад
Can we do using 2 pointer
@nikoo28
@nikoo28 4 месяца назад
Give me a pseudo code for your approach
@mdsalik9374
@mdsalik9374 10 месяцев назад
What if there is no majority element? How to handle that?
@nikoo28
@nikoo28 10 месяцев назад
then it will be an entirely different problem. What are you looking to find?
@foodandjournieswithme8788
@foodandjournieswithme8788 5 месяцев назад
It gives error when nums=[6,5,5]
@nikoo28
@nikoo28 5 месяцев назад
What error are you getting? I tried the case again and it gives 5 as the output
@foodandjournieswithme8788
@foodandjournieswithme8788 5 месяцев назад
@@nikoo28 sir i got output as 6 in the same code
@nikoo28
@nikoo28 5 месяцев назад
@@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 3 месяца назад
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++)
@mdsalik9374
@mdsalik9374 10 месяцев назад
Can we get n/3 solution as well?
@nikoo28
@nikoo28 10 месяцев назад
do you have a link to the problem?
@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]
Далее
Making an Algorithm Faster
30:08
Просмотров 106 тыс.
LeetCode 169 - Majority Element - C++
11:18
LeetCode was HARD until I Learned these 15 Patterns
13:00
Is Computer Science still worth it?
20:08
Просмотров 367 тыс.
How I would learn Leetcode if I could start over
18:03
Просмотров 569 тыс.