Python | Optimal O(n) | easy to understand
\n\n# Code\n\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        nums.sort()\n        d = {}\n        ans = 0\n        for i, 
\n\n# Code\n```\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        nums.sort()\n        d = {}\n        ans = 0\n        for i, n in enumerate(nums):\n            sqrt = n ** 0.5\n            if sqrt in d and sqrt.is_integer():\n                d[n] = d[sqrt] + 1\n                ans = max(ans, d[n])\n            else:\n                d[n] = 1\n        \n        return ans if ans > 0 else -1\n```
['Hash Table', 'Python3']