Shortest Subarray With OR at Least K II

You are given an array nums of non-negative integers and an integer k.

An array is called special if the bitwise OR of all of its elements is at least k.

Return the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.

Example 1
Inputnums = [1,2,3], k = 2
Output1
The subarray [3] has OR value of 3, so the shortest special subarray has length 1.
Example 2
Inputnums = [2,1,8], k = 10
Output3
The subarray [2,1,8] has OR value of 11, so the shortest special subarray has length 3.

Constraints

  • 1 <= nums.length <= 2 * 10^5
  • 0 <= nums[i] <= 10^9
  • 0 <= k <= 10^9

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate