Java | Array + Max Value
Code\n\nclass LUPrefix {\n\n    int res;\n    int max;\n    int[] arr;\n\n    public LUPrefix(int n) {\n        res = 0;\n        max = 0;\n        arr = new in
# Code\n```\nclass LUPrefix {\n\n    int res;\n    int max;\n    int[] arr;\n\n    public LUPrefix(int n) {\n        res = 0;\n        max = 0;\n        arr = new int[n + 1];\n    }\n\n    public void upload(int video) {\n        arr[video]++;\n        max = Math.max(video, max);\n        if (video == res + 1) {\n            res++;\n        }\n        boolean exists = true;\n        for (int i = res; i <= max; i++) {\n            if (arr[i] == 0) {\n                res = Math.max(i - 1, res);\n                exists = false;\n                break;\n            }\n        }\n        if (exists) res = max;\n    }\n\n    public int longest() {\n        return res;\n    }\n}\n```
['Java']