SImple solution without binary search
\njava []\nclass LUPrefix {\n      int max;\n      int[]l;\n      TreeSet<Integer>ts;\n     // boolean \n    public LUPrefix(int n) {\n        max=0;\n        l
\n```java []\nclass LUPrefix {\n      int max;\n      int[]l;\n      TreeSet<Integer>ts;\n     // boolean \n    public LUPrefix(int n) {\n        max=0;\n        l=new int[n+2];\n        ts=new TreeSet<>((a,b)->b-a);\n    }\n    \n    public void upload(int v) {\n        int ll=l[v-1];\n        int rl=l[v+1];\n        int nl=ll+rl+1;\n        l[v]=nl;\n        l[v-ll]=nl;\n        l[v+rl]=nl;\n\n    }\n    \n    public int longest() {\n        return l[1];\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```
['Java']