Mobile Tech
1.11K subscribers
91 photos
8 videos
6 files
136 links
Michael Lazebny's blog about @dart and @flutter
lazebny.io
Download Telegram
Today I learned an interesting algorithm for finding the majority element.

The Boyer-Moore majority algorithm is a popular algorithm for finding the majority element in a list of integers. The majority element in an array (or list) is an element that appears more than n/2 times where n is the size of the array.

Here's a simple way to describe the Boyer-Moore Voting Algorithm:

1. Start with an initial candidate and a counter set to 0.
2. Iterate over the list of numbers.
3. For the current number: If the counter is zero, set the current number as the candidate.
4. If the current number is the candidate, increment the counter. Otherwise, decrement the counter.
5. The candidate will be the majority number.

#dart #leetcode #tipoftheday #algorithm