O(nlogn) using merging lower upper bound intervals
Main Idea:\n+ Managing lower/upper bound intervals\n+ Uploading method:\n  + vmin, vmax = video, video\n  + Find upper bound interval: video - 1 -> found: vmin 
**Main Idea**:\n+ Managing lower/upper bound intervals\n+ Uploading method:\n  + vmin, vmax = video, video\n  + Find upper bound interval: video - 1 -> found: vmin = min(interval), delete lower/upper bound intervals corresponding\n  + Find lower bound interval: video + 1 -> found: vmax = max(interval), delete lower/upper bound intervals corresponding\n  + Updating lower/upper bound intervals\n+ Longest method: max(upper bound(1) \n\n**Examples**:\n```\n+ Current Status:\nlower bound intervals = {1: [1,3], 5: [5,8]}\nupper bound intervals: {3:[1,3], 8:[5,8]}\n\n+ Upload(4):\nvideo 4 -> vmin=4, vmax = 4\n\nvideo-1 = 3 => found upper bound 3: [1,3]\n-> vmin = 1, upper: {8:[5,8]}, lower: {5: [5,8]}\n\nvideo+1 = 5 => found lower bound 5: [5,8]\n-> vmax = 8, upper: {}, lower: {}\n\nUpdating: lower: {1: [1,8]}, upper: {8: [1,8]}\n\n+ Longest: lower[1][1] -> 8\n```\n\n**Code**:\n```python\nclass LUPrefix:\n    def __init__(self, n: int):\n        self.check = [0] * (n+1)\n        self.n = n\n        self.hmin = {}\n        self.hmax = {}\n\n    def upload(self, video: int) -> None:\n        if video>=1 and video<=self.n and self.check[video]==0:\n            q1 = self.hmax.get(video-1)\n            q2 = self.hmin.get(video+1)\n            vmin, vmax = [video, video]\n            if q1 is not None and q2 is not None:\n                vmin, vmax = q1[0], q2[1]\n                del self.hmax[video-1]\n                del self.hmin[video+1]\n            elif q1 is not None:\n                vmin, vmax = q1[0], video\n                del self.hmax[q1[1]]\n            elif q2 is not None:\n                vmin, vmax = video, q2[1]\n                del self.hmin[q2[0]]\n            self.hmax[vmax] = [vmin, vmax]\n            self.hmin[vmin] = [vmin, vmax]    \n            self.check[video] = 1\n            \n        # print(q1, q2, self.check, self.hmin, self.hmax)\n            \n    def longest(self) -> int:\n        if self.hmin.get(1) is None:\n            return 0\n        else:\n            return self.hmin[1][1]\n\n\n# Your LUPrefix object will be instantiated and called as such:\n# obj = LUPrefix(n)\n# obj.upload(video)\n# param_2 = obj.longest()\n```
['Python3']