Swift💯Set
Good Interview Answer (accepted answer)\nApproach: Brute Force, No Sort\n\nclass Solution {\n    func longestSquareStreak(_ nums: [Int]) -> Int {\n        let s
**Good Interview Answer (accepted answer)**\nApproach: Brute Force, No Sort\n```\nclass Solution {\n    func longestSquareStreak(_ nums: [Int]) -> Int {\n        let s = Set(nums)\n        var maxStreak = -1\n        \n        for var n in s where s.contains(n*n) {\n            var streak = 0\n            while s.contains(n) {\n                n = n*n\n                streak += 1\n            }\n            maxStreak = max(maxStreak, streak)\n        }\n        return maxStreak\n    }\n}\n```\n\n---\n\n**BONUS: One-Liner, terse (accepted answer)** \n\u26A0\uFE0F-For fun only, this is twice as slow as brute force. \n```\nclass Solution {\n    func longestSquareStreak(_ nums: [Int]) -> Int {\n        [Set(nums)].map{s in s.map{n in sequence(first: n){$0*$0}.prefix{s.contains($0)}.count}.filter{$0>1}.max() ?? -1}[0]\n    }\n}\n```\n**One-Liner, expanded and annotated (accepted answer)**\n```\nclass Solution {\n    func longestSquareStreak(_ nums: [Int]) -> Int {\n        [\n            Set(nums)\n        ] // <-- put the set of `num` into monad\n        .map{ s in\n\t\t\ts.map{ n in // we need `nums` as set, otherwise time limit exceeded\xA0(TLE)\n\t\t\t\tsequence(first: n, next:{$0*$0})\n                .prefix{n in s.contains(n)} // create seq while square streak exists\n                .count // return the count of the square streak\n            }\n            .filter{$0>1} // square streak count must be at least 2\n            .max() ?? -1 // if max subseq count < 2, return -1 else return max count\n        }.first! // <-- pull result out of monad\n    }\n}\n```
['Swift']