O(N) Approach | very easy in  java
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```java []
class LUPrefix {

    int[] fre ;
    int max ;
    int ind ;
    public LUPrefix(int n) {
        fre = new int[n + 1] ;
        max = 0 ;
        ind = 1 ;
    }
    
    public void upload(int video) {
        fre[video] = 1 ;
    }
    
    public int longest() {
        while (ind <= fre.length - 1 && fre[ind] == 1) {
            ind++;
        }
        return ind - 1;
    }
}

/**
 * Your LUPrefix object will be instantiated and called as such:
 * LUPrefix obj = new LUPrefix(n);
 * obj.upload(video);
 * int param_2 = obj.longest();
 */
```
['Java']