Simple HashMap + Sorting Question || O(nlogn) + O(n⋅log(max_value)) || C++
IntuitionApproachComplexity
Time complexity: O(nlogn) + O(n⋅log(max_value))

Space complexity: O(n)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(nlogn) + O(n⋅log(max_value))
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n)
<!-- Add 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();
        map<int,int> mp;
        for(int i = 0; i < n; i++){
            mp[nums[i]] = i;
        }

        int ans = -1;
        for(int i = 0 ; i < n; i++){
            int curr = nums[i];
            long long nxt = pow(nums[i], 2);
            if(nxt > 1e5)continue;
            int len = 1;

            if(curr != -1){
                while(mp.find(nxt) != mp.end()){
                    len++;
                    nums[mp[nxt]] = -1;
                    if(nxt > 1e6)break;
                    nxt *= nxt;
                }
            }

            ans = max(len , ans);
        }

        return ans == 1 ? -1 : ans;
    }
};
```
['C++']