Java || TreeSet || union Find
set contains all the videos which are not yet uploaded so smallest number in the TreeSet represent the smallest numbered video that needs to be uploaded.\n\n\nc
```set contains all the videos which are not yet uploaded so smallest number in the TreeSet represent the smallest numbered video that needs to be uploaded.```\n\n```\nclass LUPrefix {\n    TreeSet<Integer> set = new TreeSet<>();\n    public LUPrefix(int n) {\n        for (int i = 1; i <= n + 1; i++) {\n            set.add(i);\n        }\n    }\n    \n    public void upload(int video) {\n        set.remove(video);\n    }\n    \n    public int longest() {\n        return set.first() - 1;\n    }\n}\n```\n```Union Find```\n```\nclass LUPrefix {\n    public int find(int a) {\n        return a == par[a] ? a : (par[a] = find(par[a]));\n    }\n    \n    public void union(int a, int b) {\n        int parA = find(a);\n        int parB = find(b);\n        if (parA > parB) {\n            par[parB] = parA;\n        } else {\n            par[parA] = parB;\n        }\n    }\n    \n    int[] par;\n    boolean[] uploaded;\n    public LUPrefix(int n) {\n        par = new int[n + 2];\n        uploaded = new boolean[n + 2];\n        uploaded[0]=  true;\n        for (int i = 0; i < n + 1; i++) {\n            par[i] = i;\n        }\n    }\n    \n    public void upload(int video) {\n        uploaded[video] = true;\n        if (uploaded[video - 1]) union(video, video - 1);\n        if (uploaded[video + 1]) union(video, video + 1);\n    }\n    \n    public int longest() {\n        return find(0);\n    }\n}
[]