python/java sort + hashmap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        square = {}\n        nums.sort(reverse = True)\n        res = -1\n        for num in nums:\n            if num * num in square:\n                square[num] = square[num * num] + 1\n                res = max(res, square[num])\n            else:\n                square[num] = 1\n        return res\n\n\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Map<Integer, Integer> square = new HashMap<>();\n        Arrays.sort(nums);\n        int res = -1;\n        for (int i = nums.length - 1; i > -1; i --) {\n            int num = nums[i];\n            if (square.containsKey(num * num)) {\n                square.put(num, square.get(num * num) + 1);\n                res = Math.max(res, square.get(num));\n            } else {\n                square.put(num, 1);\n            }\n        }\n        return res;\n    }\n}\n```
['Java', 'Python3']