#2568

Minimum Impossible OR

specialist · 735 · lc medium +31 · verified · 58.9% accepted · 382 likes · top 56%

Description

Given a 0-indexed integer array nums, an integer is expressible if it equals the bitwise OR of some non-empty subsequence of nums. Return the smallest positive integer that cannot be expressed this way.

Example 1:

Input: nums = [2,1]
Output: 4
Explanation: 1 and 2 are already present in the array. We know that 3 is expressible, since nums[0] | nums[1] = 2 | 1 = 3. Since 4 is not expressible, we return 4.

Example 2:

Input: nums = [5,3,2]
Output: 1
Explanation: We can show that 1 is the smallest number that is not expressible.

Code

1
2
3