Easy NlogN solution using sorting and using a set
Intuition\n Describe your first thoughts on how to solve this problem. \nPut all the numbers is a set and sort the original array. Loop through the numbers in t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nPut all the numbers is a set and sort the original array. Loop through the numbers in the array. \nIf the number is in the set, check if its square is in the set. Keep doing this and increasing count and removing the squares and the original number from the set. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```python3 []\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        \n        numSet = set()\n        for n in nums:\n            numSet.add(n)\n        \n        nums.sort()\n        res = 1\n        \n        for n in nums:\n            if n in numSet:\n                count = 1\n                while n*n in numSet:\n                    count += 1\n                    numSet.remove(n)\n                    n = n*n\n                res = max(count, res)\n        \n        return res if res != 1 else -1\n\n```
['Python3']