6 lines with hashmap
reversing nums is better because no need to take care of float\n\n# Code\n\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n       
reversing nums is better because no need to take care of float\n\n# Code\n```\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        ans, buf = -1, {}\n        for n in reversed(sorted(nums)):\n            buf[n] = buf.get(n*n, 0) + 1\n            if buf[n] > 1:\n                ans = max(ans, buf[n])\n        return ans\n```
['Python3']