Solution using SET | no DP | no two pointer | no sliding window | no hash map
Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve this problem, we need a subsequence in nums where each element (after sorting)
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve this problem, we need a subsequence in nums where each element (after sorting) is the square of the previous one. Since sorting removes the need for a specific order, we can convert nums to a set, allowing efficient checks for squared relationships.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Set up a Pool**: We start by creating a set from the input list nums. This set, named pool, allows us to check for the presence of elements in constant time, which is efficient for our needs.\n\n2. **Iterate Through Each Element**: For each element in pool, we initiate a local count (localCount) to track the length of the current "square streak" subsequence.\n\n3. **Square Streak Check**:\n\n    - We check if the square of the current element exists in pool.\n    - If it does, we update the element to its square and increment localCount.\n    - This process continues as long as the next square exists in the set, effectively building a chain of elements where each is the square of the previous.\n4. **Update Global Count**: After each subsequence chain ends (i.e., no further squares are found), we compare localCount to a global count, updating it if localCount is greater. This ensures we always have the longest square streak.\n\n5. **Return Result**: If count remains 1 (indicating no valid streak of length at least 2 was found), we return -1. Otherwise, we return count as the length of the longest square streak.\n\nThis approach ensures we efficiently find the longest square streak by leveraging the fast lookup times provided by a set.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity is O(n log n), where \uD835\uDC5B is the number of elements in nums. This complexity arises because:\n- We iterate through each unique element, and in the worst case, we may square each element multiple times, but this is limited to \nlog max(\uD835\uDC5B\uD835\uDC62\uD835\uDC5A\uD835\uDC60) squares, as squaring grows exponentially.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity is O(n) due to storing elements in a set for efficient lookup.\n# Code\n```python3 []\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        pool = set(nums)\n\n        count = 1\n        for element in pool:\n            n = element\n            localCount = 1\n            while n*n in pool:\n                n = n*n\n                localCount += 1\n            count = max(count, localCount)\n            \n        return count if count != 1 else -1\n```\n```java []\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Set<Long> pool = new HashSet<>();\n        for (int num : nums) {\n            long n = num;\n            pool.add(n);\n        }\n\n        int count = 1;\n        for(Long element: pool){\n            long n = element;\n            int localCount = 1;\n            while (pool.contains(n*n)){\n                n = n*n;\n                localCount++;\n            }\n            count = Math.max(count, localCount);\n        }\n        return (count != 1)? count: -1;\n    }\n}\n```
['Ordered Set', 'Python3']