JAVA | HashSet | Easy ✅
Please Upvote :D\n\n---\n\n\n\n---\n\njava []\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        int maxLen = 0;\n\n        Set<Intege
# Please Upvote :D\n\n---\n\n![image.png](https://assets.leetcode.com/users/images/fdf4f9e3-644e-4c23-b7ec-78cf04322602_1670753050.7683902.png)\n\n---\n\n``` java []\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        int maxLen = 0;\n\n        Set<Integer> set = new HashSet<>();\n        for (int n : nums) {\n            set.add(n);\n        }\n\n        for (int i = 0; i < nums.length; i++) {\n            int n = nums[i];\n            int len = 1;\n\n            while (set.contains(n * n)) {\n                n *= n;\n                len++;\n            }\n\n            maxLen = Math.max(maxLen, len);\n        }\n\n        return maxLen > 1? maxLen : -1;\n    }\n}\n\n// TC: O(n) + O(n) => O(n)\n// SC: O(n)\n```
['Hash Table', 'Java']