Solving Online Majority Element In Subarray in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

Example:

MajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);
majorityChecker.query(0,5,4); // returns 1
majorityChecker.query(0,3,3); // returns -1
majorityChecker.query(2,3,2); // returns 2

Constraints:

![](https://img.halfrost.com/Leetcode/leetcode_1157_0.png)

    mc.merge = func(i, j segmentItem) segmentItem {
            if i.candidate == j.candidate {
                return segmentItem{candidate: i.candidate, count: i.count + j.count}
            }
            if i.count > j.count {
                return segmentItem{candidate: i.candidate, count: i.count - j.count}
            }
            return segmentItem{candidate: j.candidate, count: j.count - i.count}
        }

See the full details of the problem Online Majority Element In Subarray at LeetCode

Originally posted at: @github.com/halfrost/LeetCode-Go