class Solution { public: int OR(int i, int j, vector<vector<int>> &prefix) { int k = 0; for (int u = 0; u <= 30; u++) { int one; if (i == 0) one = prefix[u][j]; else one = prefix[u][j] - prefix[u][i - 1]; if (one >= 1) { k = k + (1 << u); } } return k; } int minimumSubarrayLength(vector<int>& nums, int k) { int n = nums.size(); vector<vector<int>> bit(31, vector<int>(n)); for (int j = 30; j >= 0; j--) { for (int i = 0; i < n; i++) { bit[j][i] = (nums[i] >> j) & 1; } } vector<vector<int>> prefix(31, vector<int>(n)); for (int j = 30; j >= 0; j--) { for (int i = 0; i < n; i++) { if (i == 0) prefix[j][i] = bit[j][i]; else prefix[j][i] = prefix[j][i - 1] + bit[j][i]; } } // from here the exact previous Concept Building optimization code of two pointer template is added // one thing above whole condition bitwise OR condition is added extra with respect to question the two pointer template is exact it is // 'i' pointer we rename the variable it as left // 'j' pointer we rename the variable it as right int minLength = INT_MAX; int windowSum = 0; int left = 0; for (int right = 0; right < n; ++right) { windowSum = OR(left, right, prefix); while (windowSum >= k && left <= right) { // in the whole algorithm this loop will only go from left = 0 till left = n-1 // so only total O(N) extra operations. minLength = min(minLength, right - left + 1); windowSum = OR(left + 1, right, prefix); ++left; } if (left <= right) { } else { right = left; } } if (minLength == INT_MAX) { return -1; } return minLength; } };
Standard input is empty
prog.cpp:4:26: error: ‘vector’ has not been declared
int OR(int i, int j, vector<vector<int>> &prefix)
^~~~~~
prog.cpp:4:32: error: expected ‘,’ or ‘...’ before ‘<’ token
int OR(int i, int j, vector<vector<int>> &prefix)
^
prog.cpp:25:31: error: ‘vector’ has not been declared
int minimumSubarrayLength(vector<int>& nums, int k)
^~~~~~
prog.cpp:25:37: error: expected ‘,’ or ‘...’ before ‘<’ token
int minimumSubarrayLength(vector<int>& nums, int k)
^
prog.cpp: In member function ‘int Solution::OR(int, int, int)’:
prog.cpp:12:23: error: ‘prefix’ was not declared in this scope
one = prefix[u][j];
^~~~~~
prog.cpp:14:23: error: ‘prefix’ was not declared in this scope
one = prefix[u][j] - prefix[u][i - 1];
^~~~~~
prog.cpp: In member function ‘int Solution::minimumSubarrayLength(int)’:
prog.cpp:27:17: error: ‘nums’ was not declared in this scope
int n = nums.size();
^~~~
prog.cpp:27:17: note: suggested alternative: ‘enum’
int n = nums.size();
^~~~
enum
prog.cpp:29:9: error: ‘vector’ was not declared in this scope
vector<vector<int>> bit(31, vector<int>(n));
^~~~~~
prog.cpp:29:23: error: expected primary-expression before ‘int’
vector<vector<int>> bit(31, vector<int>(n));
^~~
prog.cpp:35:17: error: ‘bit’ was not declared in this scope
bit[j][i] = (nums[i] >> j) & 1;
^~~
prog.cpp:39:23: error: expected primary-expression before ‘int’
vector<vector<int>> prefix(31, vector<int>(n));
^~~
prog.cpp:46:21: error: ‘prefix’ was not declared in this scope
prefix[j][i] = bit[j][i];
^~~~~~
prog.cpp:46:36: error: ‘bit’ was not declared in this scope
prefix[j][i] = bit[j][i];
^~~
prog.cpp:48:21: error: ‘prefix’ was not declared in this scope
prefix[j][i] = prefix[j][i - 1] + bit[j][i];
^~~~~~
prog.cpp:48:55: error: ‘bit’ was not declared in this scope
prefix[j][i] = prefix[j][i - 1] + bit[j][i];
^~~
prog.cpp:58:25: error: ‘INT_MAX’ was not declared in this scope
int minLength = INT_MAX;
^~~~~~~
prog.cpp:58:25: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
class Solution {
prog.cpp:58:25:
int minLength = INT_MAX;
^~~~~~~
prog.cpp:64:41: error: ‘prefix’ was not declared in this scope
windowSum = OR(left, right, prefix);
^~~~~~
prog.cpp:66:33: error: ‘k’ was not declared in this scope
while (windowSum >= k && left <= right)
^
prog.cpp:71:29: error: ‘min’ was not declared in this scope
minLength = min(minLength, right - left + 1);
^~~
Standard output is empty