C++ Solution with Explanation || Power of 2 || Easy to Understand
UpVote the Solution if it helps you!!\n\n# Intuition\nWe can create all the elements upto  2^(i+1) - 1 using OR operation if we have all 2\'s power upto 2^i ele
UpVote the Solution if it helps you!!\n\n# Intuition\nWe can create all the elements upto <b> 2^(i+1) - 1</b> using OR operation if we have all 2\'s power upto <b>2^i</b> element in the array.\n\nFor Example:-\n\n<ul>\n<li> If we have Arr = [1, 2], then we can have 1, 2, 3 elements after applying OR operation on Arr. As <b>1 | 2 = 3</b> <br>\n<li> Similarly, if Arr = [1,2,4], then we can have 1 - 7 elements possible\n</ul>\n\nIn simple words, if we have all the 2\'s power till 2^3 (i.e. 8) in the array, then we can generate all the elements till 2^4 - 1 i.e. 1-15 using OR operation.\n\n<b>We will not able to create 2\'s power using OR operation</b>\n\n# Approach\nNow we know that, if we have 2\'s power upto <b>2^i</b>, than we can form all the elements upto <b> 2^(i+1) - 1</b> using OR operation. \nThe solution will be the smallest 2\'s power which is not present in array.\n\n<b>So we have to find the smallest power of 2 which is not present in Array</b>\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int minImpossibleOR(vector<int>& nums) {\n\n        // Put all the elements in unordered set\n        unordered_set<int> st(nums.begin(), nums.end()); \n\n        // Initialize with smallest power of 2, i.e. 2^0\n        int ans = 1;\n\n        // Compute the next power of 2 until it is not present in set\n        while(st.find(ans) != st.end()) {\n            ans *= 2;\n        }\n        return ans;\n    }\n};\n```
['C++']