Using sqrt() function and Hashmap.
\n# Code\n\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        int ans=0;\n        sort(nums.begin(),nums.end());\n        uno
\n# Code\n```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        int ans=0;\n        sort(nums.begin(),nums.end());\n        unordered_map<float,int> mp;\n        for(int i=0;i<nums.size();i++){\n            float temp = sqrt(nums[i]);\n            if(mp.find(temp)!=mp.end()){\n                mp[nums[i]] = mp[temp]+1;\n            }\n            else{\n                mp[nums[i]]=1;\n            }\n        }\n        for(auto i:mp){\n            ans=max(ans,i.second);\n        }\n        if(ans==1) return -1;\n        return ans;\n    }\n};\n```
['C++']