Simple swift solution
\nclass LUPrefix {\n    var last = 0\n    var cache = Set<Int>()\n\n    init(_ n: Int) {}\n    \n    func upload(_ video: Int) {\n        appendIfNeeded(video)\
```\nclass LUPrefix {\n    var last = 0\n    var cache = Set<Int>()\n\n    init(_ n: Int) {}\n    \n    func upload(_ video: Int) {\n        appendIfNeeded(video)\n    }\n    \n    func longest() -> Int {\n        last\n    }\n    \n    private func appendIfNeeded(_ video: Int) {\n        if last + 1 == video {\n            self.last = video\n            processCacheIfNeeded()\n        } else {\n            cache.insert(video)\n        }\n    }\n    \n    private func processCacheIfNeeded() {\n        guard !cache.isEmpty else { return }\n        while cache.contains(last + 1) {\n            last += 1\n        }\n    }\n}\n```\n
['Swift']