[LeetCode] Minimum Impossible OR

2568. Minimum Impossible OR

You are given a 0-indexed integer array nums.

We say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < … < indexk < nums.length for which nums[index1] | nums[index2] | … | nums[indexk] = x. In other words, an integer is expressible if it can be written as the bitwise OR of some subsequence of nums.

Return the minimum positive non-zero integer that is not expressible from nums.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
int minImpossibleOR(vector<int>& A) {
unordered_set<int> us(begin(A), end(A));
for(long long i = 0; ; i++) {
long long l = 1<<i;
if(!us.count(l)) return l;
}
return -1;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/02/19/PS/LeetCode/minimum-impossible-or/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.