LeetCode solutions

3381. Shortest Subarray With OR at Least K I

My accepted Python solution to LeetCode problem 3381, Shortest Subarray With OR at Least K I, running in 2ms.

  • Difficulty: Easy
  • Python
  • Runtime 2ms
  • Memory 17.6MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 2ms, memory 17.6MB, accepted 2026-01-01.

python
class Solution:
    def minimumSubarrayLength(self, nums: List[int], k: int) -> int:
        n = len(nums)
        min_len = float('inf')
        
        for i in range(n):
            or_val = 0
            for j in range(i, n):
                or_val |= nums[j]
                if or_val >= k:
                    min_len = min(min_len, j - i + 1)
                    break
        
        return min_len if min_len != float('inf') else -1

Source