JS sort and set
Code\n### #1\n\nconst longestSquareStreak = function(nums) {\n    nums.sort((a, b) => a-b)\n    const set = new Set(nums)\n    let max = -1\n    let visited = n
# Code\n### #1\n```\nconst longestSquareStreak = function(nums) {\n    nums.sort((a, b) => a-b)\n    const set = new Set(nums)\n    let max = -1\n    let visited = new Set()\n    for (let i = 0; i < nums.length; i++) {\n        let num = nums[i]\n        if (visited.has(num)) continue;\n        let count = 0\n        visited.add(num)\n        while (set.has(num*num)) {\n            visited.add(num*num)\n            num = num*num\n            count++\n        }\n        if (count > 0) {\n            max = Math.max(max, count+1)\n        }\n    }\n    return max\n};\n```\n### #2\n```\nconst longestSquareStreak = function(nums) {\n    const set = new Set(nums)\n    let max = -1\n    for (let num of nums) {\n        let count = 0\n        while (set.has(num)) {\n            num = num*num\n            count++\n        }\n        if (count > 1) {\n            max = Math.max(max, count)\n        }\n    }\n    \n    return max\n};\n```
['JavaScript']