✔ Python3 Solution | DP | Clean & Concise
Complexity\n- Time complexity: O(nlogn)\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n    def longestSquareStreak(self, A):\n        A.sort()\n       
# Complexity\n- Time complexity: $$O(nlogn)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n    def longestSquareStreak(self, A):\n        A.sort()\n        n = len(A)\n        dp = [1] * n\n        r = n - 1\n        for i in range(n - 1, -1, -1):\n            while A[i] * A[i] < A[r]: r -= 1\n            if A[i] * A[i] == A[r]: dp[i] = dp[r] + 1\n        ans = max(dp)\n        return ans if ans > 1 else -1\n```
['Dynamic Programming', 'Sorting', 'Python3']