Simple java solution
\n\n# Complexity\n- Time complexity: O(n logn) for sorting + O(n) for traversing the loop\n\n- Space complexity: O(n) --> For storing elements in the hashmap\n\
\n\n# Complexity\n- Time complexity: O(n logn) for sorting + O(n) for traversing the loop\n\n- Space complexity: O(n) --> For storing elements in the hashmap\n\n# Code\n```\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Arrays.sort(nums);\n        Map<Integer,Integer> nm=new HashMap<>();\n        int p=-1,s=-1;\n        for(int i=0;i<nums.length;i++)\n        {\n            int m=(int)Math.sqrt(nums[i]);\n            if(m*m == nums[i] && nm.containsKey(m))\n            {\n                nm.put(nums[i],nm.get(m)+1);\n                if(nm.containsKey(m))\n                {\n                    if(nm.get(m)+1>s)\n                    {\n                        s=nm.get(m)+1;\n                    }\n                }\n            }\n            else\n            {\n                nm.put(nums[i],1);\n            }\n        }\n        return s;\n    }\n}\n\n```
['Hash Table', 'Java']