C++ || DP || Binary Search
\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) \n    {\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\n    
```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) \n    {\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\n        vector<int>dp(n, 0);\n        dp[n - 1] = 1;\n        int mxLen = 1;\n        for (int i = n - 2; i >= 0; i--)\n        {\n            long long target = (long long)nums[i] * nums[i];\n            //======================================================\n            int low = i + 1, high = n - 1;\n            int pos = -1;\n            while(low <= high)\n            {\n                int mid = low + (high - low) / 2;\n                if (nums[mid] == target) { pos = mid; break; }\n                else if (nums[mid] < target) low = mid + 1;\n                else if (nums[mid] > target) high = mid - 1;\n            }\n            //=========================================================\n            int currLen;\n            if (pos == -1) currLen = 1;\n            else currLen = 1 + dp[pos];\n            dp[i] = currLen;\n            mxLen = max(dp[i], mxLen);\n        }\n        if (mxLen == 1) return -1;\n        return mxLen;\n        \n    }\n};\n\n```
['C', 'C++']