C++ | Easy Understanding
Self Explanatory Solution\n\nclass LUPrefix {\npublic:\n    int ans=0;\n    vector< int >isUpdated;\n    \n    LUPrefix( int n ) {\n        isUpdated.assign( n+
Self Explanatory Solution\n\n```class LUPrefix {\npublic:\n    int ans=0;\n    vector< int >isUpdated;\n    \n    LUPrefix( int n ) {\n        isUpdated.assign( n+2 , 0 );\n    }\n    \n    void upload( int video ) {\n        isUpdated[ video ] = 1;\n        while ( isUpdated[ ans + 1 ] == 1 )\n        {\n            ans++;\n        }   \n    }\n    \n    int longest() {\n        return ans;\n    }\n};\n```\n\n**Fenwick Tree based Solution**\n\nUse binary search to find count of elements from 1 to k\n\nif the count == k, this shows that answer can be k or more than that\n\nTo find the count, we use fenwick tree\n\n```class LUPrefix {\npublic:\n    vector< int >fen;\n    int N;\n    void update ( int i )\n    {\n        while( i < N )\n        {\n            fen[ i ]++;\n            i += ( i&-i );\n        }\n    }\n    int query( int i )\n    {\n        int ans = 0;\n        while( i > 0 )\n        {\n            ans += fen[i];\n            i -= ( i&-i );\n        }\n        return ans;\n    }\n    \n    LUPrefix( int n ) {\n        N = n + 2;\n        fen.assign( n + 5 , 0 );\n        \n    }\n    void upload( int video ) {\n        update( video );\n    }\n    int longest() {\n        int l = 0, h = N - 1 , ans = 0;\n        while(l <= h)\n        {\n            int m = ( l + h ) / 2;\n            if( query( m ) == m )\n            {\n                ans = m;\n                l = m + 1;\n            }\n            else{\n                h = m - 1;\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'Binary Tree']