3095. Shortest Subarray With OR at Least K I Easy
1/**
2 * [3095] Shortest Subarray With OR at Least K I
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 * Note that [2] is also a special subarray.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">nums = [2,1,8], k = 10</span>
19 * Output: <span class="example-io">3</span>
20 * Explanation:
21 * The subarray [2,1,8] has OR value of 11. Hence, we return 3.
22 * </div>
23 * <strong class="example">Example 3:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [1,2], k = 0</span>
26 * Output: <span class="example-io">1</span>
27 * Explanation:
28 * The subarray [1] has OR value of 1. Hence, we return 1.
29 * </div>
30 *
31 * Constraints:
32 *
33 * 1 <= nums.length <= 50
34 * 0 <= nums[i] <= 50
35 * 0 <= k < 64
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i/
41// discuss: https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn minimum_subarray_length(nums: Vec<i32>, k: i32) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3095() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.