Java Priority Queue Solution
\nclass LUPrefix {\n    \n    PriorityQueue<Integer> pq;\n    int previousValue;\n\n    public LUPrefix(int n) {\n        pq = new PriorityQueue<>();\n        p
```\nclass LUPrefix {\n    \n    PriorityQueue<Integer> pq;\n    int previousValue;\n\n    public LUPrefix(int n) {\n        pq = new PriorityQueue<>();\n        previousValue = 0;\n    }\n    \n    public void upload(int video) {\n        pq.offer(video);\n        \n        while(!pq.isEmpty() && pq.peek().equals(previousValue + 1)) {\n            pq.poll();\n            previousValue += 1;\n        }\n    }\n    \n    public int longest() {\n        return previousValue;\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 ```\n \n Time complexity :- 0(nlogn)
[]