LeetCode 169. Majority Element - Interview Prep Ep 73 | Boyer–Moore majority vote algorithm

preview_player
Показать описание

LeetCode 169. Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
You may assume that the array is non-empty and the majority element always exist in the array.

Example 1:
Input: [3,2,3]
Output: 3

Example 2:
Input: [2,2,1,1,1,2,2]
Output: 2

Solutions explained:

Time complexity: O(n)
Space complexity: O(1)

⭐ Support my channel and connect with me:

// TOOLS THAT I USE:

// MY FAVORITE BOOKS:

My ENTIRE Programming Equipment and Computer Science Bookshelf:

And make sure you subscribe to my channel!

Your comments/thoughts/questions/advice will be greatly appreciated!

#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Рекомендации по теме
Комментарии
Автор

you're vids are great even today, ty fisher

DaBigWang
Автор

Nicely explained steve. This channel is a goldmine for leetcode problems

sugandhm
Автор

You're channel is underrated. I find your explanations more understandable and clearer than more famous channels😅

mikedepacina
Автор

Like your approach for giving multiple solution of a problem and explanation of each problem.

nishantkumar
Автор

Best content. Thanks for the video brother.

DecentProgrammer
Автор

Subscribed, and I don't regret it. You're a genius....

KaisarAnvar
Автор

Well explained. I understand how this works now. Subscribed.

SK-ybbx
Автор

I Like your videos, you make things so easy. good job

dinamohamed
Автор

ok thats pretty cool. you are a good teacher. thank you <3

thomasstephenson
Автор

Thanks this video was helpful. Could you make a video on segment tree?

VasheshJ
Автор

Hi There,

Thanks for the explanation, it’s pretty clear and to the point.
Would you mind explaining other areas/questions where this algorithm can be utilized.

chaitanyarao
Автор

nice explanation! thanks for sharing this video!

lxkp
Автор

thanks a lottt for this easy yet best explaination. you saved my whole day😊

sharanvkt
Автор

Thank you!! It didn't strike me that I can also sort and get middle element!! 😊 Video was helpful!

pds
Автор

I don't think you've added enough #fishercode tags in your video.

zfarahx
Автор

Clear explanation, I understood it just by watching once. Appreciate 💪

lilaiyang
Автор

Was looking for a more optimal space solution, thanks!

justinkuang
Автор

Nice explanation. A minor question: why when counter == 0, candidate is reset to nums[i] while we do not increase counter from 0 to 1 (I mean do "counter++"). Based on your explanation, this should be the case.

guo
Автор

at 6 20, you said counter start from 0 but int counter = 1 initially. I am confused, do you mind explaining? Great video btw thanks!

sysybaba
Автор

Nice explanation, but for this [10, 9, 9, 9, 10] as input I am getting the wrong answer.

amitbhattacharya