id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\n private:\n bool consecutive(vector<int>& arr) {\n for (int i = 0; i < arr.size() - 1; i++) {\n if (arr[i] + 1 != arr[i + 1]) {\n return false;\n }\n }\n return true;\n }\n\n int maxelem(vector<int>& arr) {\n int...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool isConsecutiveAndSorted(const vector<int>& subarray) {\n for(int i=1;i<subarray.size();i++)\n {\n if(subarray[i]!=subarray[i-1]+1)\n {\n return false;\n }\n }\n return true;\n }\n vector<int...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool isConsecutiveAndSorted(const vector<int>& subarray) {\n for(int i=1;i<subarray.size();i++)\n {\n if(subarray[i]!=subarray[i-1]+1)\n {\n return false;\n }\n }\n return true;\n }\n vector<int...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool isSortedAndisConsecutive(const vector<int>& subarray) {\n bool isSorted = true;\n bool isConsecutive = true;\n for (int i = 0; i < subarray.size() - 1; ++i) {\n if (subarray[i] > subarray[i + 1]) {\n isSorted = false;\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> ans;\n for(int i=0;i<n-k+1;i++){\n vector<int> curr(k,0);\n int ind=0;\n int maxi=INT_MIN;\n for(int j=i;j<i+k;j++){\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "#include <vector>\n#include <algorithm>\n#include <unordered_set>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> result;\n int n = nums.size();\n \n for (int i = 0; i <= n - k; ++i) {\n vect...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n\n int power(vector<int> nums){\n for(int i = 0; i+1 < nums.size(); ++i){\n if(nums[i] + 1 != nums[i+1]) return -1;\n }\n\n return nums.back();\n }\n\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> window;\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int r = nums.size();\n int c = nums.size();\n int n = r;\n vector<vector<bool>>dp(r, vector<bool>(c, false));\n\n for (int i = 0; i<r; i++){\n dp[i][i] = true;\n f...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int>res;\n if(k==1) return nums;\n vector<int>w(nums.begin(),nums.begin()+k);\n for(int i=0;i<nums.size()-k+1;i++){\n res.push_back(helper(w));\n if(i+k<nums.size()...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "#define sz(v) (ll)v.size()\n#define lp(i, n) for(int i = 0 ; i < n ; i++)\n#define rep(i, v) for(int i = 0; i < sz(v) ; i++)\n#define all(v) v.begin(), v.end()\n#define allr(v) v.rbegin(), v.rend()\n#define lpd(i, a, b) for(int i = a ; i >= b ; i--)\n#define lpi(i, a, b) for(int i = a ; i < b ; i++)\n#defi...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n vector<int>ans;\n for(int i=0;i<=nums.size()-k;i++){\n vector<int> arr(nums.begin() + i, nums.begin() + i + k);\n ans.push_back(check(arr));\n }\n return ans;\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int>ans;\n for(int i=0;i<=nums.size()-k;i++){\n vector<int> arr(nums.begin() + i, nums.begin() + i + k);\n ans.push_back(check(arr));\n }\n return ans;\n \n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "\n#include<deque>\nclass Solution {\npublic:\n bool issortandcons(vector<int> & nums)\n {\n for(int i = 1;i<nums.size();++i)\n {\n if ((nums[i] - nums[i-1] != 1 ) || (nums[i] < nums[i-1]))\n return false; \n }\n return true;\n }\n\n \n ve...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "\n#include<deque>\nclass Solution {\npublic:\n bool issortandcons(vector<int> & nums)\n {\n for(int i = 1;i<nums.size();++i)\n {\n if ((nums[i] - nums[i-1] != 1 ) || (nums[i] < nums[i-1]))\n return false; \n }\n return true;\n }\n\n \n ve...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool isSorted(vector<int> vec){\n vector<int> sorted=vec;\n sort(sorted.begin(),sorted.end());\n return vec==sorted;\n }\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int> result;\n for(int...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<vector<int>> subarray;\n vector<int> sub;\n\n for(int i = 0; i < nums.size(); ++i) {\n sub.push_back(nums[i]);\n\n if(sub.size() == k) {\n subarray.push_bac...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<vector<int>> in;\n int b=0;\n vector<int> temp,res;\n while(b<nums.size())\n {\n temp.push_back(nums[b]);\n if(temp.size()==k)\n {\n in.push_back(tem...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n\n vector<vector<int>> arr;\n vector<int> ans;\n\n for (int i = 0; i < n - k + 1; i++) {\n ans.clear(); // Clear ans for each subarray\n for (int j ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\nprivate:\n bool checkConsecutive(vector<int>&nums)\n {\n for(int i=1;i<nums.size();i++)\n {\n if(nums[i] != nums[i-1]+1)\n {\n return 0;\n }\n }\n return 1;\n }\n bool checkSorted(vector<int>&nums)\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool checkConsecutive(vector<int> inp)\n {\n for(int i=0;i<inp.size()-1;i++)\n {\n if(inp[i+1]!=inp[i]+1)\n return false;\n }\n return true;\n }\n vector<int> resultsArray(vector<int>& nums, int k) {\n int ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\n\nprivate:\n bool consec(vector<int> vec)\n {\n for (size_t i = 1; i < vec.size(); ++i) {\n if (vec[i] != vec[i - 1] + 1) {\n return false; // Not consecutive\n }\n }\n return true;\n }\n\npublic:\n vector<int> resultsA...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool helper(vector<int>v){\n for(int i=0;i<v.size()-1;i++)\n {\n if(v[i+1]-v[i]!=1)\n return false;\n }\n return true;\n }\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n =nums.size();\n vector<int>ans;\n for(int ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> v;\n int n = nums.size();\n\n \n if (k > n) {\n v.push_back(-1);\n return v;\n }\n\n for (int i = 0; i <= n - k; i++) {\n \n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n if(nums.size() == 1) {\n return nums;\n }\n int n = nums.size();\n vector<int> result;\n\n for(int i = 0; i <= n - k; i++) {\n \n vector<int> t...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\nbool is_sort(vector<int>v)\n{\n for(int i=0;i<v.size()-1;i++)\n {\n if(v[i]>=v[i+1])\n {\n return false;\n }\n }\n return true;\n}\nbool is_cons(vector<int>v)\n{\n for(int i=0;i<v.size()-1;i++)\n {\n if(v[i]+1!=v[i+1])\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int>res;\n int n = nums.size();\n \n for(int i=0;i<=n-k;i++)\n {\n vector<int>temp;\n int f = 1;\n temp.push_back(nums[i]);\n for(int j...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n vector<int> ans;\n for(int i=0;i<=nums.size()-k;i++){\n int prev = nums[i];\n vector<int> v;\n v.push_back(prev);\n for(int j=i+1;j<i+k;j++){\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n\n\n for(int i=0;i<=nums.size()-k;i++){\n vector<int> ds;\n\n int size = k;\n int pos = i;\n while(size--){\n if(ds.empty() || ds....
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> v;\n for(int i =0;i <= n-k; i++){\n vector<int> ans;\n int maxi = INT_MIN;\n bool flag = true;\n for(int j = 0; j <k; j++...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n int n = nums.size();\n queue<int> q;\n vector<int> ans;\n int a = 0;\n for(int i = a+k;i <= n ;i ++){\n vector<int> temp;\n temp.push_back(nums[a]);\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>ans;\n for(int i=0;i<=n-k;i++)\n {\n \n vector<int>v;\n int x=nums[i];\n v.push_back(nums[i]);\n for(int j...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n int n = nums.size();\n for(int i=0;i<=n-k;++i){\n vector<int> v1,v2;\n int f=0;\n for(int j=0;j<k;++j){\n if(j>0){\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n int t=0;\n int n=nums.size();\n vector<int>res(n-k+1);\n for(int i=0;i<n && t<n-k+1;i++)\n { vector<int> temp,x;\n int flag=0;\n for(int j=i;j<i+k-1;j++...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int mini=100001;\n int i=0;\n int j=0;\n vector<int>e;\n vector<int>ans;\n while(j<nums.size()){\n if((j-i+1)<k){\n e.push_back(nums[j]);\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n \nvector<int> helper(vector<int>& arr ,int k,unordered_map<int,int>mp) {\n int n = arr.size();\n k--;\n vector<int>ans;\n bool flag2=false;\n for (int i = 0; i <= n - k; ++i) {\n flag2=!flag2;\n vector<int> sub(arr.begin() + i, arr.begin() + i +...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n\n for(int i = 0; i <= n - k; i++) {\n vector<int> temp;\n\n bool isValid = true;\n temp.push_back(nums[i]);\n\n fo...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "#include <vector>\n#include <unordered_set>\n#include <algorithm>\n\n#include <vector>\n#include <unordered_set>\n#include <algorithm>\n\nclass Solution {\npublic:\n std::vector<int> resultsArray(std::vector<int>& nums, int k) {\n std::vector<int> results;\n int n = nums.size();\n \...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(const vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n for (int i = 0; i <= n - k; i++) {\n vector<int> temp(nums.begin() + i, nums.begin() + i + k);\n \n if (check(temp)) {\...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n for(int i=0;i<(n-k+1);i++)\n {\n stack<int> s;\n s.push(nums[i]-1);\n int maxi = 0;\n for(int j=i;j<i+k;j++...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>final;\n int flag=0;\n for(int i=0;i<(n-(k-1));i++){\n stack<int>st;\n for(int j=i;j<(i+k);j++){\n if(st.empty()||(st.top()=...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n int index1 = 0;\n int index2 = (k - 1);\n int index3 = 0;\n\n vector<int> res;\n\n while (index2 < nums.size()) {\n \n stack<int> stk; \n bool act = true;\...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n\n for(int i=0 ; i<=nums.size()-k ; i++){\n stack<int> st;\n\n bool valid=true;\n for(int j=i ; j<i+k ; j++){\n if(j==i){\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n\n for(int i=0 ; i<=nums.size()-k ; i++){\n stack<int> st;\n\n bool valid=true;\n for(int j=i ; j<i+k ; j++){\n if(j==i){\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool isPower(vector<int> nums, int r1, int r2){\n for(int i = r1 ; i < r2 - 1 ; i++){\n if(nums[i+1] != nums[i] + 1) return false;\n }\n return true;\n }\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n vector<int...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\nprivate:\n bool isConsecutive(const vector<int>& arr) {\n int minVal = *min_element(arr.begin(), arr.end());\n int maxVal = *max_element(arr.begin(), arr.end());\n\n // Check if the range is exactly k-1\n if (maxVal - minVal != arr.size() - 1) {\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "#include <vector>\n#include <algorithm>\n#include <unordered_set>\n\nclass Solution {\npublic:\n bool areConsecutive(const std::vector<int>& arr) {\n if (arr.empty()) return false;\n\n int minElement = *std::min_element(arr.begin(), arr.end());\n int maxElement = *std::max_element(a...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "typedef long long ll;\n#define rep(i,a,b) for(ll i=a;i<b;i++)\n#define repr(i,a,b) for(ll i=a;i>=b;i--)\n#define PNO cout<<\"NO\\n\"\n#define PYES cout<<\"YES\\n\"\n#define vll vector<ll>;\n#define all(x) x.begin(),x.end()\nint M=1e9+7;\n\nclass Solution {\npublic:\n vector<int>resultsArray(vector<int>&...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int>ans;\n for(int c=0;c<nums.size()-k+1;c++){\n stack<int>st;\n bool nots = false;\n int count =0;\n while(count<k){\n int value = c+count;\...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n bool is_conseq(deque<int>dq){\n int t=dq.front();\n dq.pop_front();\n while(!dq.empty()){\n if(dq.front()-t!=1)return false;\n t=dq.front();\n dq.pop_front();\n }\n return true;\n }\n vector<int> result...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n \n void solve(vector<int>&ans,queue<int>qu,int k){\n int curr = qu.front();\n qu.pop();\n int next = qu.front();\n qu.pop();\n \n // cout<<\"curr \"<<curr<<endl;\n // cout<<\"next \"<<next<<endl;\n \n if(next...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> results(n - k + 1);\n for (int i = 0; i <= n - k; ++i) {\n vector<int> subarray(nums.begin() + i, nums.begin() + i + k);\n \n vector<int> sortedSubarray = s...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "#include <deque>\n#include <vector>\n\nclass Solution {\n\n private:\n bool isSorted(const deque<int>& sub) {\n for (int i = 1; i < sub.size(); i++) {\n if (sub[i] != sub[i - 1] + 1) {\n return false;\n }\n }\n return true;\n }\n \n i...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> results;\n \n for (int i = 0; i <= n - k; ++i) {\n vector<int> subarray(nums.begin() + i, nums.begin() + i + k);\n vector<int> sorted_subarray = subarray;\...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\nbool check(vector<int>a){\n for(int i=0;i<a.size()-1;i++){\n if(a[i+1]!=a[i]+1) return false;\n }\n return true;\n}\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>ans;\n for(int i=0;i<n-k+1;i++){\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n int solve(vector<int>& temp) {\n vector<int> original = temp;\n sort(temp.begin(), temp.end());\n\n if (temp != original) {\n return -1;\n }\n\n for (int i = 1; i < temp.size(); ++i) {\n if (temp[i] != temp[i - 1] + 1) ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size(); \n vector<int> results(n - k + 1); \n for (int i=0; i <= n-k; i++) { \n vector<int> subarray(nums.begin() + i, nums.begin() + i + k); \n vector<int> uniqueEle(suba...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n deque<int>dq;\n vector<int>ans;\n int n=nums.size();\n for(int i=0;i<n;i++){\n dq.push_back(nums[i]);\n if(dq.size()>=k){\n deque<int>d=dq;\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int>result;\n queue<int>q;\n for (int i =0; i<nums.size();i++){\n q.push(nums[i]);\n if (q.size()==k){\n queue<int>c = q;\n int element =c.fr...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define loop(i, a, n) for (lli i = (a); i < (n); ++i)\n#define loopD(i, a, n) for (lli i = (a); i >= (n); --i)\n#define all(c) (c).begin(), (c).end()\n#define rall(c) (c).rbegin(), (c).rend()\n#define sz(a) ((int)a.size())\n#define YES cout << \"YES\" << en...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> results(n - k + 1);\n \n for (int i = 0; i <= n - k; ++i) {\n vector<int> subarray(nums.begin() + i, nums.begin() + i + k);\n vector<int> sorted_subarray = suba...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n int solve(queue<int> q){\n int ans=-1;\n int s=q.front();\n q.pop();\n \n while(!q.empty()){\n if(q.front()!=s+1) return -1;\n s=q.front();\n q.pop();\n }\n \n return s;\n }\n vecto...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n int isSorted(queue<int>q){\n \n int prev = q.front();\n int maxi = prev;\n q.pop();\n while(!q.empty()){\n int top = q.front();\n q.pop();\n maxi = max(maxi, top);\n if(top > prev && prev+1 == top)...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& a, int k) {\n int n= a.size();\n vector<int>ans;\n for(int i=0;i<=n-k;i++){\n vector<int>t(a.begin() + i, a.begin() + i + k);\n vector<int>s=t;\n sort(s.begin(),s.end());\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> results;\n \n for (int i = 0; i <= n - k; ++i) {\n vector<int> subarray(nums.begin() + i, nums.begin() + i + k);\n vector<int> sortedSubarray = subarray...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\n int func(vector<int> &nums, int st, int lt, int k){\n vector<int> a(nums.begin() + st, nums.begin() + lt + 1);\n vector<int> b(nums.begin() + st, nums.begin() + lt + 1);\n if(b[0] == b[b.size() - 1] && (k != 1)) return -1;\n sort(a.begin(), a.end());\n ...
3,522
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
3
{ "code": "class Solution {\npublic:\n void func(const vector<int>& nums, int start, int k, vector<int>& ans) {\n vector<int> a(nums.begin() + start, nums.begin() + start + k);\n vector<int> b = a;\n sort(b.begin(), b.end());\n for(int i = 1; i < b.size(); i++){\n if(b[i] == ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> result(n - k + 1, -1);\n \n if (n < k) return result;\n\n // Check initial window\n bool isValidWindow = true;\n for (int i = 1; i < k; +...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n if(k==1)return nums;\n vector<int> ans(n-k+1,-1);\n\n int cnt=0;\n \n for(int i=1;i<k;i++){\n if(nums[i]!= nums[i-1]+1)cnt++;\n }\n i...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size(), last = 0;\n vector<int> res(n - k + 1, -1);\n for (int i = 1; i < k; i++){\n if (nums[i] != 1 + nums[i - 1]) last = i;\n }\n for (int i = k - 1, j = 0; i ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(k == 1) return nums;\n int n = nums.size();\n int streak = 1;\n vector<int> result(n - k + 1, -1);\n for(int i = 1; i < n; i++) {\n if(nums[i] - nums[i - 1] == 1) {\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n int dp[n];\n // dp[i] = length of longest subarray ending at i \n // that has cosecutive and sorted elements\n dp[0] = 1;\n for (int i = 1; i < n; i++) {\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<bool>check(n);\n if(k==1)return nums;\n int rec=nums[0];\n int len=1;\n if(k==1)check[0]=true;\n for(int i=1;i<n;i++){\n if(nums[i]-r...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "#include <vector>\n#include <deque>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans(n - k + 1, -1);\n deque<int> dq;\n\n \n bool flag = true;\n for (int i = 1; i <...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n if(k==1) return nums;\n vector<pair<int,int>> p;\n vector<int> ans(n-k+1,-1);\n int x=0, y=0;\n for(int i=0; i<n-1; i++) {\n if(nums[i+1]!=nums[i]+...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(k==1)\n return nums;\n\n vector<pair<int,int>> consecutive;\n int n = nums.size();\n vector<int> ans(n-k+1,-1);\n int start=0,end = 1;\n bool flag = false;\n whil...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>res(n-k+1,-1);\n vector<int>temp(nums.begin(),nums.begin()+k);\n int check=0,prob=-1;\n for(int i=0;i<k-1;i++)\n {\n if(nums[i]+1!=nums[...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if (k == 1) return nums;\n int i, n = nums.size(), sum = nums[0];\n vector<int> ans(n - k-- + 1, -1);\n unordered_map<int, int> freq;\n for (i = n; --i;) nums[i] -= nums[i - 1];\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n if(k==1)return nums;\n unordered_map<int,int>hm;\n vector<int>v(n-k+1,-1);\n int i=0,j=0;\n while(j<k-1){\n hm[nums[j+1]-nums[j]]++;\n j+...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n queue<int>q;\n if( k == 1) return nums;\n vector<int> res(nums.size() - k + 1, -1);\n for (int i = 0; i <= nums.size() - k; i++) {\n bool flag = true;\n if( !q.empty() ){\...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> res(n-k+1,-1);\n if (k == 1) {\n for (int i = 0; i < n-k+1; ++i) {\n res[i] = nums[i];\n }\n return res;\n }\n...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n// int n = nums.size();\n// vector<int> result(n - k + 1, -1);\n// stack<int> fa;\n\n// int maxElement = nums[0];\n// for (int i = 1; i <= n - k; ++i) {\n// if (nums[i] != nums[i - 1...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n if (k == 1) return nums;\n \n vector<int> ans(n - k + 1);\n deque<int> breaks;\n \n // Preprocess to find breaks in consecutive elements\n for...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> sto;\n int sz = 0;\n vector<int> ans(n - k + 1, -1);\n for (int i = 0; i < n; i++) {\n sto.push_back(nums[i]);\n sz++;\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans(n - k + 1);\n vector<int> v;\n for( int i = 0 ; i < k-1 ; i++ ){\n if( v.size() == 0 ) v.push_back( nums[i] );\n else{\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n int n = nums.size();\n vector<int> result(n - k + 1);\n deque<int> dq;\n\n for (int i = 0; i < n; i++)\n {\n while (!dq.empty() && nums[dq.back()] + 1 != nums[i])\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=nums.size();\n deque<int> dq;\n vector<int> res(n-k+1,-1);\n int i=0,j=0;\n\n while(j<n){\n while(j<n && j-i+1<=k) {\n if(dq.size() && dq.back()-nums[j]!=...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> lookup(nums.size(), 0);\n for (int i = 1; i < nums.size(); ++i)\n lookup[i] = (nums[i] == nums[i - 1] + 1) * (1 + lookup[i - 1]);\n\n vector<int> ans(nums.size() - k + 1, -1);\n...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n \n int n=nums.size();\n \n vector<int>ans(n-k+1),order(n);\n \n order[0]=1;\n for(int i=1;i<n;i++)\n {\n order[i]=nums[i]-nums[i-1]==1?1:-1;\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\npublic:\n\n vector<int> resultsArray(vector<int>& nums, int k) {\n\n if (k == 1) return nums;\n\n\n vector<int> ans;\n\n\n int n = nums.size();\n\n int i = 1, consecutiveSize = 1;\n\n while (i < n) {\n\n if (nums[i] - 1 == nums[i - 1]) {\n\...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
0
{ "code": "class Solution {\n public:\n // Same as 3254. Find the Power of K-Size Subarrays I\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n int start = 0;\n\n for (int i = 0; i < nums.size(); ++i) {\n if (i > 0 && nums[i] != nums[i - 1] + 1)\n start = i;\n if ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> res;\n int n = nums.size();\n int count = 1;\n\n for (int i = 0; i < n; i++) {\n if (i > 0 && nums[i - 1] + 1 == nums[i]) {\n count += 1;\n } el...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n int i=0;\n vector<int>ans;\n int ct=1;\n for(int j=0;j<nums.size();++j){\n if(j>=1 && nums[j]==nums[j-1]+1){\n ct++;\n }else{\n ct=1;\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int t) {\n if(t==1) return nums;\n int i=0,j=0;\n vector<int>v;\n deque<int> dq;\n int val = nums[0];\n dq.push_back(nums[0]);\n bool flag = true;\n int idx = -1;\n whil...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int t) {\n if(t==1) return nums;\n int i=0,j=0;\n vector<int>v;\n deque<int> dq;\n dq.push_back(nums[0]);\n bool flag = true;\n int idx = -1;\n while(j<nums.size()-1){\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(nums.size()==1) return {nums[0]};\n // bool check = true;\n vector<bool> satisfied;\n for(int i=0; i<nums.size()-1; i++){\n bool check = true;\n if(nums[i]+1!=nums[i+1]...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& a, int k) {\n \n int i,j,n=a.size();\n map<int,int>mk;\n vector<int>ans(n,-1);\n vector<int>dp(n,1);\n dp[0]=1;\n if(k==1){\n for(i=0;i<n;i++){\n ans[i]=a[i];\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution{\npublic:\n vector<int> resultsArray(vector<int>& nums, int k){\n // Approach: \n // Self Solved \n // TC : \n // SC : \n // C++ CODE: \n vector<int> ans; // to store the power of each subarrray of size 'k' \n int i = 0; // Window Start (Po...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(k==1) return nums;\n vector<int> ans;\n int count = 1;\n int start = 0,end = 1;\n while(end<nums.size()){\n if(count==k){\n ans.push_back(nums[end-1]);\n ...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) \n {\n if(nums.size()==1)\n return {nums[0]};\n if(k==1)\n return nums;\n\n unordered_map<int,int> diffMap;\n for(int i=1; i<k; i++)\n {\n int diff=nums[i...
3,523
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p> <p>The <strong>power</strong> of an array is defined as:</p> <ul> <li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>...
2
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& a, int k) {\n int n = a.size();\n vector<int> ans(n - k + 1, -1);\n vector<int> pr(n + 1, 0);\n for(int i = 1; i < n; i++) {\n pr[i] = pr[i - 1] + ((a[i] - a[i - 1] == 1) ? 1 : 0);\n }\n ...