JAVA Solution time beats 100% || space beats 100%
\n# Complexity\n- Time complexity: O(n)\n \n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\n    public int 
\n# Complexity\n- Time complexity: O(n)\n \n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Set<Long> set = new HashSet<>();\n\n        for(int i: nums) set.add(Long.valueOf(i));\n\n        int max = 0;\n        for(int i: nums) {\n            int cnt = 1;\n            long num = i;\n\n            while(set.contains(num*num)) {\n                num = num*num;\n                cnt++;\n            }\n\n            max = Math.max(max, cnt);\n        }\n\n        return max == 1 ? -1: max;\n    }\n}\n```
['Hash Table', 'Java']