Minimum Impossible OR - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2]
›
Output:
4
💡 Note:
1 OR 2 = 3. Expressible: 1, 2, 3. Missing: 4 is the minimum positive integer not expressible.
Example 2 — Single Element
$
Input:
nums = [5]
›
Output:
1
💡 Note:
Only 5 is expressible. 1 is the minimum positive integer not expressible.
Example 3 — Multiple Elements
$
Input:
nums = [3,1]
›
Output:
2
💡 Note:
Expressible: 1, 3, 1|3=3. So expressible are {1,3}. Minimum missing: 2.
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Given array of positive integers
2
OR Combinations
All possible OR values from subsequences
3
Find Minimum
Smallest positive integer not expressible
Key Takeaway
🎯 Key Insight: OR can only set bits - if no number has bit k set, then 2^k cannot be formed
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code