✅C++ | ✅Easy to Understand
Intuition\nWe can make any number with power of 2 (we need to also insure that we have previous power number as well).\nLike we can make \n- 1 (with power 0), \
# Intuition\nWe can make any number with power of 2 (we need to also insure that we have previous power number as well).\nLike we can make \n- 1 (with power 0), \n- 2,3 (with power 0 and 1), \n- 4,5,6,7 (with power 0,1 and 2)and so on.\n\n# Approach \nWe mark perfect power of 2 elements like 1,2,4,8,16 in the array then we check which minimum element is not available and return that element.   \n\n# Complexity\n- Time complexity:\nO(nx30) ~ O(n)\n\n- Space complexity:\nO(31) ~ O(1)\n\n# Code\n```\nclass Solution \n{\n    \npublic:\n    bool checkPowerOfTwo(int n) \n    {\n        while(n!=1)\n        {\n            if(n%2==1) return false;\n            n /= 2;\n        }\n        return true;\n    }\n    int minImpossibleOR(vector<int>& nums) \n    {\n        vector<int> binary(31, 0);\n        int cnt;\n        \n        for(auto it:nums)\n        {\n            if(checkPowerOfTwo(it)) //elements like 1,2,4,8,16\n            {\n                cnt=0;\n                while(it)\n                {\n                    it /= 2;\n                    cnt++;\n                }\n                binary[cnt-1]=1; //mark power needed to form the element\n            }\n        }\n        \n        int num;\n        for(int i=0; i<31; i++) //find minimum not available element by using power\n        {\n            if(binary[i]!=1)\n            {\n                num = (int) pow(2, i); //form that element\n                break;\n            }\n        }\n        return num; \n    }\n};\n```\n\n# Please upvote if you like this approach
['Array', 'Math', 'C++']