c++, 1-line pruning improves it from TLE to beat 100%
\nclass MajorityChecker {\npublic:\n    MajorityChecker(vector<int>& arr) {\n        for(int i=0; i< arr.size(); i++){\n            v2ind[arr[i]].push_back(i);\
```\nclass MajorityChecker {\npublic:\n    MajorityChecker(vector<int>& arr) {\n        for(int i=0; i< arr.size(); i++){\n            v2ind[arr[i]].push_back(i);\n        }\n        for(auto it = v2ind.begin(); it != v2ind.end(); it++){\n            countvs.emplace_back(it->second.size(), it-> first);\n        }\n        sort(countvs.begin(), countvs.end(), [](pair<int, int>& p1,pair<int, int>& p2 ){\n            if(p1.first > p2.first) return true;\n            else if (p1.first==p2.first) return p1.second > p2.second;\n            else return false;\n            \n        });\n    }\n    \n    int query(int left, int right, int threshold) {\n        for(auto p: countvs)\n        {\n            int v =p.second;\n            int c = p.first;\n            if(c < threshold) return -1;  // this pruning helps improve from TLE to 100%\n            auto& inds = v2ind[v];\n            auto lit = lower_bound(inds.begin(), inds.end(), left);\n            auto  uit = upper_bound(inds.begin(), inds.end(), right);\n            int count = uit - lit;\n            if(count >= threshold) return v;\n        }\n        return -1;\n    }\n    unordered_map<int, vector<int>> v2ind;\n    vector<pair<int, int>> countvs;\n};\n```
[]