Python3 O(N) Solution with count sorting (99.05% Runtime)
IntuitionApproach
Define an array for count sorting and iteratively update corresnponding index.
Return the current index of the array and update it if needed.
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
![image.png](https://assets.leetcode.com/users/images/f75dbcb1-3c79-483c-b947-316d04e029f0_1740120766.964825.png)

# Approach
<!-- Describe your approach to solving the problem. -->
- Define an array for count sorting and iteratively update corresnponding index.
- Return the current index of the array and update it if needed.

# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
If this solution is similar to yours or helpful, upvote me if you don't mind
```python3 []
class LUPrefix:

    def __init__(self, n: int):
        self.n=n
        self.m=n+1
        self.a=[False]*(self.m)
        self.i=1
        
    def upload(self, video: int) -> None:
        self.a[video]=True 
        
    def longest(self) -> int:
        while self.i<=self.n and self.a[self.i]:
            self.i+=1
        return self.n if self.i==self.m else self.i-1

# Your LUPrefix object will be instantiated and called as such:
# obj = LUPrefix(n)
# obj.upload(video)
# param_2 = obj.longest()
```
['Array', 'Math', 'Design', 'Queue', 'Counting', 'Monotonic Queue', 'Counting Sort', 'Python', 'Python3']