:: Kotlin :: Boyer-Moore Majority Vote
\nclass MajorityChecker(val arr: IntArray) {\n    fun query(left: Int, right: Int, threshold: Int): Int {\n        var major = Int.MAX_VALUE\n        var sum = 
```\nclass MajorityChecker(val arr: IntArray) {\n    fun query(left: Int, right: Int, threshold: Int): Int {\n        var major = Int.MAX_VALUE\n        var sum = 0\n\n        for (i in left .. right) {\n            val num = arr[i]\n\n            if (num == major) {\n                sum += 1\n            } else if (sum == 0) {\n                major = num\n                sum += 1\n            } else {\n                sum -= 1\n            }\n        }\n        \n        sum = 0\n        for (i in left .. right) {\n            if (arr[i] == major) {\n                sum += 1\n            }\n        }\n\n        return if( sum >= threshold ) major else -1\n    }\n\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */\n```
['Kotlin']