Easy Solution Using Max & Min Heap
\n\n# Code\n\nclass LUPrefix {\npublic:\n    priority_queue<int>q;\n    priority_queue<int,vector<int>,greater<int>>q2;\n    int prev;\n    LUPrefix(int n) {\n 
\n\n# Code\n```\nclass LUPrefix {\npublic:\n    priority_queue<int>q;\n    priority_queue<int,vector<int>,greater<int>>q2;\n    int prev;\n    LUPrefix(int n) {\n        prev=0;\n    }\n    \n    void upload(int video) {\n        q.push(video);\n        q2.push(video);\n    }\n    \n    int longest() {\n        if(!q.empty() && q.size()==q.top())return q.top();\n        else if(!q2.empty()){\n            int res=prev;\n            while(res+1==q2.top()){\n                res++;\n                q2.pop();\n            }\n            prev=res; \n            return res;             \n\n        }\n        else \n        return 0;\n    }\n};\n\n/**\n * Your LUPrefix object will be instantiated and called as such:\n * LUPrefix* obj = new LUPrefix(n);\n * obj->upload(video);\n * int param_2 = obj->longest();\n */\n```
['Heap (Priority Queue)', 'C++']