java – Boyer–Moore vote algorithm returns wrong result

I needed to find the majority element in a list and came across Boyer–Moore algorithm,

So I applied it as recommended, the thing is if the majority elements are consecutive it is returning correct result, but if not it returns the wrong one

These are the results after I run for the same array in a different array.

Is there any other case needed to consider to implement this algorithm?

It seems like a popularly accepted algorithm and kind of surprised to get the wrong result.

Thanks.

0
3

package main;

public class FindMajority {

    public static void main(String() args) {

        int() array = {3, 2, 3, 1, 0, 3 };
        System.out.println( findMajority(array) );

        int() array1 = {3, 3, 3, 2, 0, 1 };
        System.out.println( findMajority(array1) );

    }

    public static int findMajority(int() arr) {

        int m = 0;
        int i = 0;
        for(int x: arr) {

            if(i == 0) {
                m = x;
                i = 1;
            } else if (m == x) {
                i = i + 1;
            } else {
                i = i - 1;
            }
        }
        return m;
    }

}