Leetcode 229 - Majority Element II (Moore Voting Algorithm)

preview_player
Показать описание
Hi Gophers!
Here's the Golang solution for Leetcode 229, Majority Element II (code beats 96% of Go submissions)
We use the Boyer-Moore Majority Vote Algorithm and cover mathematical explanation with analogy, visualisation and examples.

Solve this as part of the top 150 leetcode interview questions or for leetcode medium questions preparation.

0:00 Introduction
0:21 Question
0:51 The Intuition: 3 Key Steps
1:12 An Analogy: Boyer-Moore Majority Vote Algorithm
2:10 Visualise the Solution Example
3:26 Mathematical Explanation for Algorithm
4:50 Important link and algorithm notes
5:36 Coding it out

Mathematical explanation and visualisation based on reference link:

Try Majority Element I with the same algorithm and approach:

Explore other playlists here:
1. Top 150 leetcode questions:
2. Top Common Array leetcode questions:
3. Medium leetcode questions:

All the best for your coding interviews! :)

#leetcode #codinginterview
#golang #golangtutorial #golanginterview
Рекомендации по теме
Комментарии
Автор

Although the algo works and we've to verify the elements with a second pass, but the explanation provided at 04:25 is not correct. A contradictory example is the False positive shown at 5:22

_mradultiwari_