Naïve working solution in Python
Approach\nCache the counter for subarrays.\n\n# Code\n\nclass MajorityChecker:\n\n    def __init__(self, arr: List[int]):\n        self.arr = arr\n    \n    @fu
# Approach\nCache the counter for subarrays.\n\n# Code\n```\nclass MajorityChecker:\n\n    def __init__(self, arr: List[int]):\n        self.arr = arr\n    \n    @functools.cache\n    def sub_arr_ctr(self, left: int, right: int):\n        return collections.Counter(self.arr[left:right+1])\n\n    def query(self, left: int, right: int, threshold: int) -> int:\n        c = self.sub_arr_ctr(left, right).most_common(1)[0]\n        return c[0] if c[1] >= threshold else -1\n```
['Python3']