3097. Shortest Subarray With OR at Least K II Medium

@problem@discussion
#Array#Bit Manipulation#Sliding Window



1/**
2 * [3097] Shortest Subarray With OR at Least K II
3 *
4 * You are given an array nums of non-negative integers and an integer k.
5 * An array is called special if the bitwise OR of all of its elements is at least k.
6 * Return the length of the shortest special non-empty <span data-keyword="subarray-nonempty">subarray</span> of nums, or return -1 if no special subarray exists.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [1,2,3], k = 2</span>
11 * Output: <span class="example-io">1</span>
12 * Explanation:
13 * The subarray [3] has OR value of 3. Hence, we return 1.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [2,1,8], k = 10</span>
18 * Output: <span class="example-io">3</span>
19 * Explanation:
20 * The subarray [2,1,8] has OR value of 11. Hence, we return 3.
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [1,2], k = 0</span>
25 * Output: <span class="example-io">1</span>
26 * Explanation:
27 * The subarray [1] has OR value of 1. Hence, we return 1.
28 * </div>
29 *  
30 * Constraints:
31 * 
32 * 	1 <= nums.length <= 2 * 10^5
33 * 	0 <= nums[i] <= 10^9
34 * 	0 <= k <= 10^9
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-ii/
40// discuss: https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-ii/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn minimum_subarray_length(nums: Vec<i32>, k: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_3097() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.