[Python] Union Find
\n# Code\n\nclass LUPrefix:\n\n    def __init__(self, n: int):\n        self.videos = list(range(n + 1))\n        self.uploaded = [1] + [0] * (n + 1)\n\n    def
\n# Code\n```\nclass LUPrefix:\n\n    def __init__(self, n: int):\n        self.videos = list(range(n + 1))\n        self.uploaded = [1] + [0] * (n + 1)\n\n    def upload(self, video: int) -> None:\n        self.uploaded[video] = 1\n        if self.uploaded[video + 1]: self.union(video, video + 1)\n        if self.uploaded[video - 1]: self.union(video, video - 1)\n\n    def union(self, u, v):\n        x, y = self.find(u), self.find(v)\n        if x > y: self.videos[y] = x\n        elif y > x: self.videos[x] = y\n\n    def find(self, u):\n        if u == self.videos[u]: return u\n        self.videos[u] = self.find(self.videos[u])\n        return self.videos[u]\n\n    def longest(self) -> int:\n        return self.find(0)\n```
['Union Find', 'Python3']