Short DP (C++/Java) || LIS type
For every number we reach, we just check if its a perfect square:\n   + If its a Perfect Square, we pair up with its Square Root.\n   + Else, we keep it in dp a
+ # For every number we reach, we just check if its a `perfect square`:\n   + If its a `Perfect Square`, we pair up with its `Square Root`.\n   + Else, we keep it in `dp` array with length as `1`, for pairing up its `square number` later.\n \n Similar Question : [1218. Longest Arithmetic Subsequence of Given Difference](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference/#:~:text=Input%3A%20arr%20%3D%20%5B1%2C,subsequence%20is%20any%20single%20element.)\n# C++    \n\tint longestSquareStreak(vector<int>& A) {\n        unordered_map<int, int> dp;\n        int res = 0;\n        sort(begin(A), end(A));\n        for(auto i : A){\n            int root = sqrt(i);\n            if(root * root == i)\n\t\t\t   dp[i] = 1 + dp[root];\n\t\t\telse \n\t\t\t   dp[i] = 1;\n            res = max(res, dp[i]);\n        }\n        return res < 2 ? -1 : res;\n    }\n# Java\n    public int longestSquareStreak(int[] A) {\n        HashMap<Integer, Integer> dp = new HashMap<>();\n        int res = 0;\n        Arrays.sort(A);\n        for(var i : A){\n            int root = (int)Math.sqrt(i);\n            if(root * root == i)  \n\t\t\t   dp.put(i, dp.getOrDefault(root, 0) + 1);\n            else  \n\t\t\t   dp.put(i, 1);\n            res = Math.max(res, dp.get(i));\n        }\n        return res < 2 ? -1 : res;\n    }\n> Time : O(nlogn)\n\n> Space - O(n)
['C', 'Java']