We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 13a11ed + eedef8a commit 780e8aaCopy full SHA for 780e8aa
3097. Shortest Subarray With OR at Least K II
@@ -0,0 +1,53 @@
1
+class Solution {
2
+public:
3
+ int minimumSubarrayLength(vector<int>& nums, int k) {
4
+
5
+ int n = nums.size();
6
+ int z = *max_element(nums.begin(), nums.end());
7
8
+ if(z >= k)
9
+ return 1;
10
11
+ int ans = INT_MAX;
12
+ int x = nums[0];
13
+ int i = 0;
14
+ int j = 1;
15
16
+ while(j < n)
17
+ {
18
+ x |= nums[j];
19
+ if(x < k)
20
21
+ j++;
22
+ }
23
+ else
24
25
+ ans = min(ans, j - i + 1);
26
+ while(i < n && i <= j && x >= k)
27
28
29
30
+ if(nums[i] == nums[i+1])
31
32
+ i++;
33
34
35
36
37
+ x = nums[i];
38
+ for(int t = i + 1; t <= j; t++)
39
40
+ x |= nums[t];
41
42
43
44
45
46
47
48
+ if(ans == INT_MAX)
49
+ return -1;
50
51
+ return ans;
52
53
+};
0 commit comments