C++ simple solution with video explanation
\n    #define M 32\n    int bit[20005][32];\n    vectorocc[20005]; //positions of a elements in array\n    \n    MajorityChecker(vector& arr) {\n        \n     
\n    #define M 32\n    int bit[20005][32];\n    vector<int>occ[20005]; //positions of a elements in array\n    \n    MajorityChecker(vector<int>& arr) {\n        \n        for(int i=0;i<arr.size();i++){\n            \n            occ[arr[i]].push_back(i);\n            \n            bitset<M>s(arr[i]);\n            \n            for(int j=0;j<32;j++){\n                \n                bit[i+1][j]=bit[i][j];\n                \n                if(s[j]==1)\n                    bit[i+1][j]++;\n            }\n        }\n        \n    }\n    \n    bool verify(int cand,int threshold,int left, int right) {\n        \n        //candidate occurance between left to right in array\n        \n        int candidate_occ = upper_bound(occ[cand].begin(),occ[cand].end(),right) - lower_bound(occ[cand].begin(),occ[cand].end(),left) ;\n        \n        if(candidate_occ>=threshold)\n            return true;\n        \n        return false;\n    }\n    \n    int query(int left, int right, int threshold) {\n        \n        int len = right-left+1;\n        \n        int candidate = 0;\n        \n        for(int j=0;j<32;j++){\n            \n            if(bit[right+1][j]-bit[left][j]>=threshold)\n                candidate+=(1<<j);\n        }\n        \n        if(verify(candidate,threshold,left,right))\n            return candidate;\n        \n        return -1;\n        \n    }\n};\n\n \n This is my solution. Tme complexity O(query * 32)+O(query * log(size_of_subarray)) = O(query * log(n) );\n \n video link to explain "finding majority element in array using bitmask"\n https://www.youtube.com/watch?v=0s3zqYaDInE&t=494s\n \n Thank  you.
[]