C++ | Vector | Pointer | Well Commented | O(n) solution
Please upvote if you like!!\n\nTC: O(n)\nSC: O(n)\n\nclass LUPrefix {\npublic:\n\t// we will use a vector to keep track of the uploaded videos\n    vector<int> 
**Please upvote if you like!!**\n\nTC: O(n)\nSC: O(n)\n``` \nclass LUPrefix {\npublic:\n\t// we will use a vector to keep track of the uploaded videos\n    vector<int> v;\n    int pointer;\n    \n    LUPrefix(int n) {\n\t\t// initialize the vector of size (n+1) as the video indexes start from 1 to n\n        v.resize(n+1, 0);\n\t\t// pointer will keep track of the longest uploaded prefix\n\t\t// eg. at first it will be at v[0] indicating that first video is not uploaded\n        pointer = 0;\n    }\n    \n    void upload(int video) {\n\t\t// keep track of which video is uploaded\n        v[video]++;\n\t\t\n\t\t// increment the pointer so that it points to the maximum index till which all videos are uploaded\n        for(int x=pointer+1; x<v.size(); x++){\n            if(v[x] != 0){\n                pointer = x;\n            } else if(v[x] == 0){\n                break;\n            }\n        }\n    }\n    \n    int longest() {\n\t\t// just return the pointer\n        return pointer;\n    }\n};\n\n/**\n * Your LUPrefix object will be instantiated and called as such:\n * LUPrefix* obj = new LUPrefix(n);\n * obj->upload(video);\n * int param_2 = obj->longest();\n */\n```
['C']