Wrong solution that got accepted. Can you make a test case for it?
Hi,\n\nHere is my wrong solution that got accepted.\nHere is a challange:\nCan you tell me what is wrong with it and can you invent a test case that it won\'t p
Hi,\n\nHere is my wrong solution that got accepted.\nHere is a challange:\nCan you tell me what is wrong with it and can you invent a test case that it won\'t pass?\n\nThanks and regards,\nTodor\n```\nclass MajorityChecker {\npublic:\n    vector<int> A;\n    \n    int BSZ;\n    \n    unordered_map<int,pair<int,int> > INTER;\n    vector<vector<pair<int, int> > > V;\n        \n    MajorityChecker(vector<int>& arr) {\n        A = arr;\n        BSZ = max(10, (int) sqrt(arr.size()));\n        unordered_map<int, int> M;\n        int prev = 0;\n        \n        for (int i = 0; i <= arr.size(); ++i) {\n            if (i % BSZ == 0 || i == arr.size()) {\n                set<pair<int, int>, greater<pair<int,int> > > VP;\n                for (auto& x : M) {\n                    VP.insert({x.second, x.first});\n                    if (VP.size() > 2) VP.erase(*VP.rbegin());\n                }\n                INTER[prev] = {i-1, V.size()};\n                prev = i;\n                V.push_back({});\n                for (auto& x : VP) {\n                    V.back().push_back(x);\n                }\n                \n                if (i == arr.size()) break;\n                M.clear();\n            }\n            M[A[i]]++;\n        }\n    }\n    \n    int query(int left, int right, int threshold) {\n        unordered_map<int, int> candidates;\n        for (int i = left; i <= right; ++i) {\n            if (INTER.count(i) && INTER[i].first <= right) {\n                for (auto& x : V[INTER[i].second]) {\n                    candidates[x.second] += x.first;\n                }\n                i = INTER[i].first;\n            } else {\n                candidates[A[i]]++;\n            }\n        }\n        int xv = -1, xc = 0;\n        int xv1 = -1, xc1 = 0;\n        for (auto& x : candidates) {\n            if (xc < x.second) {\n                xc1 = xc;\n                xv1 = xv;\n                xv = x.first;\n                xc = x.second;\n            } else if (xc1 < x.second) {\n                xv1 = x.first;\n                xc1 = x.second;\n            }\n        }\n        \n        \n        INTER[left] = {right, V.size()};\n        \n        V.push_back({});\n        V.back().push_back({xc1, xv1});\n        V.back().push_back({xc, xv});\n        \n        return xc >= threshold ? xv : -1;\n    }\n};\n```
[]