Beats 99% - simple boolean array  O(1) Amortized
IntuitionCreate a boolean array of size n.
Keep track of where the longest prefix should be (initially 0);
Decrement each video for easier indexing.
If we uploa
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Create a boolean array of size `n`.
Keep track of where the longest prefix should be (initially 0);
Decrement each video for easier indexing. 
If we upload a video to longest position, then we know we have a block of at least length longest, i.e., from [0, longest]. Then, we can scan adjacent cells to the right that are true, incrementing total and giving us the total size of longest. 


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

# Complexity
- Time complexity:
Amortized Complexity of upload(int video)
Worst Case:
In a single upload, the while loop may iterate over 𝑂(𝑛) indices (e.g., when all elements in mem are true after the upload).
Best Case:
The while loop does not execute (e.g., if the uploaded video index is not equal to longest).

Key Observation: The longest variable is only incremented and updated once per index during the lifetime of the program. This means the total work across all calls to upload is proportional to 𝑂(𝑛)

Thus, the amortized time complexity of each call to upload is O(1).



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

# Code
```java []
class LUPrefix {
    boolean[] mem;
    int longest = 0;
    public LUPrefix(int n) {
        mem = new boolean[n];
    }
    
    public void upload(int video) {
        video--;
        mem[video]=true;
        if (video == longest){
            longest++;
            while (longest < mem.length && mem[longest]){
                longest++;
            }
        }
    }
    
    public int longest() {
        return longest;
    }
}

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