C++ using set || DP not required || Very Simple and Easy to Understand
\n\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        int ans = 0;\n        sort(nums.begin(), nums.end());\n        unordere
\n```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        int ans = 0;\n        sort(nums.begin(), nums.end());\n        unordered_set<int> s;\n        for(auto n: nums) s.insert(n);\n        for(auto n: nums) {\n            \n            long long t = n;\n            int c = 0;\n            while(s.find(t) != s.end()){\n                c++;\n                s.erase(t);\n                t = t*t;\n            }\n            ans = max(ans, c);\n        }\n        return ans<2?-1:ans;\n    }\n};\n```
['C++']