C++ || Set || Simple Explanation
Approach:\n\n keep storing the values in the set\n keep track of the max_length\n whenever we encounter the longest() function\n\t start from the last stored ma
**Approach:**\n\n* keep storing the values in the set\n* keep track of the max_length\n* whenever we encounter the longest() function\n\t* start from the last stored max value\n\t* now keep increasing it to the number that has not been added yet\n* example:\n\t* let currently m = 3\n\t* set = {1,2,3,5,6,7,9}\n\t* because the longest has all number from 1 to i that\'s why m is 3\n\t* now we add 4\n\t* now we got the longest() function\n\t\t* so start from 3\n\t\t* check if we have 4 in the set, we do have 4 so inc m\n\t\t* after doing this ... we will reach at 7 the new max value\n\t\t* so return 7\n\n**Code:**\n\n```\nclass LUPrefix\n{\npublic:\n    set<int> st;\n    int m = 0; // max value so far\n    LUPrefix(int n)\n    {\n    }\n\n    void upload(int video)\n    {\n        st.insert(video);\n    }\n\n    int longest()\n    {\n        while (st.find(m + 1) != st.end())\n            m++;\n        return m;\n    }\n};\n```
['C', 'Ordered Set']