✔️ 100% Fastest Swift Solution
\nclass Solution {\n    func longestConsecutive(_ nums: [Int]) -> Int {\n        var map: [Int: (Int,Int)] = [:]\n        var max = 0\n        \n        for num
```\nclass Solution {\n    func longestConsecutive(_ nums: [Int]) -> Int {\n        var map: [Int: (Int,Int)] = [:]\n        var max = 0\n        \n        for num in nums {\n            if map[num] == nil {\n                let left = map[num - 1]\n                let right = map[num + 1]\n                \n                if let left = left, let right = right {\n                    map[num] = (left.0 + 1, right.1 + 1)\n                \n                } else if let left = left {\n                    map[num] = (left.0 + 1, 0)\n                \n                } else if let right = right {\n                    map[num] = (0, right.1 + 1)\n                \n                } else {\n                    map[num] = (0, 0)\n                }\n                \n                let lower = num - map[num]!.0\n                let upper = num + map[num]!.1\n                map[lower] = (0, upper - lower)\n                map[upper] = (upper - lower, 0)\n                let count = upper - lower + 1\n                max = max > count ? max : count\n            }\n        }\n        \n        return max\n    }\n    \n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']