Simple solution using Map
Intuition\n Describe your first thoughts on how to solve this problem. \nIn the first glance it looked like Longest Increasing Subsequence(LIS), but then realiz
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn the first glance it looked like Longest Increasing Subsequence(LIS), but then realized we just need to look for one element, it\'s square.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort the array. Loop on the array and check if it\'s square root is present or not. Store the length of subsequence using an unordered map. If it\'s present we can add our current element to the subsequence, else start a new subsequence.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        unordered_map<int, int> ump;\n        int res = 0;\n        for(int i = 0; i < nums.size(); i++)\n        {\n            int temp = sqrt(nums[i]);\n            if(temp * temp == nums[i] && ump[temp])\n            {\n                ump[nums[i]] = ump[temp] + 1;\n                res = max(res, ump[nums[i]]);\n            }\n            else\n                ump[nums[i]] = 1;\n        }\n        if(res == 0)\n            return -1;\n        return res;\n    }\n};\n```
['Array', 'Hash Table', 'Sorting', 'C++']