Unordered set ! O(n) easy to understand approach for substring size questions C++
Intuition\nsubstring problems just call the inner hash user in me. \nPS:idk bitset yet \n\n# Approach\n- Create a unordered set from the input vector/array.\n- 
# Intuition\nsubstring problems just call the inner hash user in me. \nPS:idk bitset yet \n\n# Approach\n- Create a unordered set from the input vector/array.\n- iteratively find strings in the vector by checking if the square of it exists in hash/unordered set.\n- We can use the check before the while loop to check if its the start of substring like *sqrt of i dosnt exist in unordered set* which can be useful when the substring can go to a very high no. unlike the max 5 length here.\n- even Long long cant keep squares of 10^5 even when its limit is 10^18 so we just stopped when k goes outside the limit 10^5 of a single element. PS: can lmk in comments if you know how would 10^5^2 goes more than long long int size ??\n\n# Complexity\n\n- ##### Time complexity:\n  O(n)\n  *still gotta calc the TC of that inner while loop*\n\n- ##### Space complexity:\n  O(n)\n\n### Pls consider upvoting if it helped !! kinda new to this\nThanks for all the views !! if theres any suggestion do lmk, will give proper time for writing solutions with detailed intuition and approaches next time i do :0\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        unordered_set<int> numSet(nums.begin(), nums.end());\n\n        int maxStreakLength = 0;\n\n        for (int num : nums) {\n            int streakLength = 0;\n\n            long long currentNum = num;\n\n            while (numSet.count(currentNum)) \n            {\n                streakLength++;\n                currentNum = currentNum * currentNum; \n                if (currentNum > 100000) break; //bcz the element value cannot be more than 10^5 so :0\n            }\n\n            maxStreakLength = max(streakLength, maxStreakLength);\n\n        }\n\n        return (maxStreakLength > 1) ? maxStreakLength : -1;\n    }\n};\n\n```
['Hash Table', 'C++']