Very easy O(N) solution (no need to sort)
Intuition\nFound this question similar to question where we have to find longest-consecutive-sequence\nhttps://leetcode.com/problems/longest-consecutive-sequenc
# Intuition\nFound this question similar to question where we have to find longest-consecutive-sequence\nhttps://leetcode.com/problems/longest-consecutive-sequence/description/\n\n# Approach\nStore all numbers intially in a map(no need to sort)\n\nItterate over the array and try to find all consecutive numbers in array\n\nLike for eg. we are standing at 2\nwe try to find 4, then 16\n\nImp-> remember to erase numbers we have founded so that there is no overlap\nSee solution for more clarity \n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        unordered_map<long long int,long long int>mp;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(mp.find(nums[i])==mp.end())\n            mp[nums[i]]++;\n        }\n        long long int ans=1;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(mp.find(nums[i])==mp.end())\n            {\n                continue;\n            }\n            long long int count=mp[nums[i]];\n            if(nums[i]<(INT_MAX/nums[i]))\n            {\n                long long int x=nums[i]*nums[i];\n                while(mp.find(x)!=mp.end())\n                {\n                    count=count+mp[x];\n                    mp.erase(x);\n                    if(x>(INT_MAX/x))\n                    {\n                        break;\n                    }\n                    x=x*x;\n\n                }\n            }\n            mp[nums[i]]=count;\n            ans=max(ans,count);\n        }\n        if(ans<2)\n        {\n            return -1;\n        }\n        return ans;\n    }\n};\n```
['C++']