DFS Approach✅✅
Approach\n Describe your approach to solving the problem. \n1. First i made a graph using the conditions of square\n2. Did a simple dfs on the graph and found t
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. First i made a graph using the conditions of square\n2. Did a simple `dfs` on the graph and found the max length of the component in the graph\n3. For better understanding see the code->> \n\n# Complexity\n- Time complexity: `O(NLog(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    bool isSquare(int n){\n        int x = sqrt(n);\n        return n == x*x;\n    }\n    void dfs(int node, map<int, int>& vis, map<int, int>& mp, int& cnt){\n        vis[node] = 1;\n        if(vis.find(mp[node]) == vis.end() && mp[node]!=0){\n            cnt++;\n            // cout<<mp[node]<<" ";\n            dfs(mp[node], vis, mp, cnt);\n        }\n    }\n    int longestSquareStreak(vector<int>& nums) {\n        map<int, int> mp, mpp;\n        for(auto it: nums) mpp[it]++;\n        //build the graph->\n        for(int i=0; i<nums.size(); i++){\n            int n = sqrt(nums[i]);\n            if(isSquare(nums[i]) && mpp.find(n)!=mpp.end()){\n                mp[n] = nums[i];\n            }\n        }\n        if(mp.size() == 0) return -1;\n        int maxi=0;\n        //do dfs on the graph\n        map<int, int> vis;\n        for(auto it: mp){\n            int node = it.first;\n            if(vis.find(node) == vis.end()){\n                int cnt=1;\n                // cout<<node<<endl;\n                dfs(node, vis, mp, cnt);\n                // cout<<endl;\n                maxi = max(maxi, cnt);\n            }\n        }\n        return maxi;\n    }\n};\n```
['Depth-First Search', 'C++']