[Python 3] Only update left and right endpoints | Time O(1), Space O(N)
If we maintain a list for all the segments so far, the longest uploaded prefix essentially is the size of the first element a.k.a self.P[1] in my case for avoid
If we maintain a list for all the segments so far, the longest uploaded prefix essentially is the size of the first element a.k.a `self.P[1]` in my case for avoiding index overflow.\n\nThe only tricky part is the way to update left&right most endpoints: \n1. find left most endpoint(`x-self.P[x-1]`) and rightmost endpoint(`x+self.P[x+1]`)\n2. update the whole segment by summing up two segments and plus more element (`self.P[x-1]+self.P[x+1]+1`)\n\n```\nclass LUPrefix:\n    def __init__(self, n: int):\n        self.P = [0]*(n+2)\n\n    def upload(self, x: int) -> None:\n        self.P[x-self.P[x-1]] = self.P[x+self.P[x+1]] = self.P[x-1]+self.P[x+1]+1\n\n    def longest(self) -> int:\n        return self.P[1]\n```
['Python']