Set with Optimizations
Many ways to solve this problem.\n\n## Set\nHere, we insert small values (< 317), and values with an integer square root, into a sorted set.\n\nThen, for each s
Many ways to solve this problem.\n\n## Set\nHere, we insert small values (< 317), and values with an integer square root, into a sorted set.\n\nThen, for each small value, we check it\'s square root sequence.\n\n**C++**\n```cpp\nint longestSquareStreak(vector<int>& n) {\n    int res = 0;\n    set<int> s;\n    for(int val : n)\n        if (int sr = sqrt(val); val < 317 || sr * sr == val)\n            s.insert(val);\n    for (auto it = begin(s); it != end(s) && *it < 317; ++it) {\n        int sz = s.size();\n        for (int i = *it; i < 317 && s.count(i * i); i *= i)\n            s.erase(i * i);\n        res = max(res, sz - (int)s.size());\n    }\n    return res == 0 ? -1 : res + 1;\n}\n```
['C']