C++ || HAshing
\n# Code\n\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        unordered_map<long lon
\n# Code\n```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        unordered_map<long long, int> mp;\n        long long res = -1;\n        for(auto n : nums) mp[n]++;\n        \n        for(auto n : nums) {\n            if(!mp.size())\n                break;\n            if(mp.count(n) != 0) {\n                long long cnt = 1, cur = (long long)n * (long long)n;\n                while(mp.size()) {\n                    if(mp.count(cur)) {\n                        mp.erase(cur);\n                        ++cnt;\n                        cur *= cur;\n                    }\n                    else\n                        break;\n                }\n                if(cnt > 1)\n                    res= max(res, cnt);\n            }\n        }\n        return res;\n    }\n};\n```
['C++']