C++ || Easy & Simple || Amortized O(1) || 100% faster
\nclass LUPrefix {\npublic:\n    vector<bool>uploaded;\n    int size;\n    int longestPrefix;\n    LUPrefix(int n) {\n        size = n;\n        uploaded.resize
```\nclass LUPrefix {\npublic:\n    vector<bool>uploaded;\n    int size;\n    int longestPrefix;\n    LUPrefix(int n) {\n        size = n;\n        uploaded.resize(size + 1, false);\n        longestPrefix = 0;\n    }\n\n    void upload(int video) {\n        uploaded[video] = true;\n    }\n\n    int longest() {\n        while ((longestPrefix + 1 <= size) && uploaded[longestPrefix + 1]) {\n            longestPrefix++;\n        }\n        return longestPrefix;\n    }\n};\n```\n**Time Complexity : O(1)**\n**Space Complexity : O(n)**\n\n\n![image](https://assets.leetcode.com/users/images/3d421ec9-fb49-4acb-a5df-5c631082e8e7_1664687215.5785422.png)
['C', 'C++']