Java + HashMap || O(n*logn)
\n# Complexity\n- Time complexity:\nO(n*logn)\n\n# Code\n\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Arrays.sort(nums);\n     
\n# Complexity\n- Time complexity:\nO(n*logn)\n\n# Code\n```\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Arrays.sort(nums);\n        HashMap<Integer, Integer> map = new HashMap<>();\n        for(int i=nums.length-1; i>=0; i--) \n            map.put(nums[i], map.getOrDefault(nums[i]*nums[i], 0) +1);\n        int max = 0;\n        for(int val : map.values())\n            max = Math.max(max, val);\n        return max == 1 ? -1 : max;\n    }\n}\n```
['Java']