beter solution using  unordered set
dd your space complexity here, e.g. O(n) -->Code
dd your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:

    int longestSquareStreak(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        int n=nums.size();
        unordered_set<int>uset(nums.begin(),nums.end());
        int ans=-1;
        for(auto it:uset)
        {
            int cnt=0;
            long long elem=it;
            while(elem<INT_MAX && uset.count(elem))
            {
                cnt++;
                elem*=elem;
            }
            ans=max(ans,cnt);
        }

        if(ans>=2)return ans;
        return -1;

    }
};
```
['Array', 'Hash Table', 'Dynamic Programming', 'Sorting', 'C++']