[JavaScript] Using bits (68ms beats 100%)
Intuition\nAny number can be used to construct numbers equal to or larger than it, we need to find the smallest 2^n number that is not present in the array\n\n#
# Intuition\nAny number can be used to construct numbers equal to or larger than it, we need to find the smallest $$2^n$$ number that is not present in the array\n\n# Approach\nIterate through the array, if a number is $$2^n$$ then apply it to the bitmask, there are a few ways to do this but using the built in clz32 Math method is a simple way to **C**ount **L**eading **Z**eros of a 32bit binary representation of a JavaScript Number. If the number is equal to a number created with only one bit set in the same most significant location then we can also set that bit in our mask.\n\nOnce all numbers have been applied to the mask we need to find the lowest unset bit, the answer will be a number with only this bit set.\n\nTo do this we invert the bitmask which means we now need to find the lowest set bit, this is easily done with `n&-n`\n\n# Complexity\n- Time complexity:\n$$O(n)$$ as we iterate the whole array once\n\n- Space complexity:\n$$O(1)$$ as we only store a single number\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minImpossibleOR = function(nums) {\n    let bits = 0\n    for (const n of nums) {\n\n        // construct a number with only the msb of n set\n        const msb = 1 << (31 - Math.clz32(n))\n        if (n == msb) {\n            // if it is the same as n (i.e. has only 1 bit set) \n            // apply it to the mask\n            bits |= msb\n        }\n    }\n\n    // to find the least significant unset bit invert the \n    // bitmask and now it is the least significant set bit\n    // 1100011011\n    //        ^ what bit is this?\n\n    // 0011100100\n    //        ^ its this bit when inverted\n\n    bits = ~bits\n    return bits & -bits\n};\n```
['Bit Manipulation', 'JavaScript']