id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\nprivate:\n const int mod=1e9+7;\npublic:\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n int m=*max_element(nums.begin(),nums.end());\n vector<vector<long long>> dp(n+1,vector<long long>(m+1,0));\n vector<int> pref(2001), pref2(2001,0);\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int solve(int i, int k, int bound, vector<int>& nums, vector<vector<int>>& dp, vector<vector<bool>>& visited) {\n if (i > nums.size()) {\n dp[i][k] = 0;\n return 0;\n }\n if (dp[i][k] > 0 || visited[i][k]) {\n...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <vector>\n#include <algorithm>\n#include <limits>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int mod = 1'000'000'007;\n int n = nums.size();\n int ma = *max_element(nums.begin(), nums.end());\n \n // In...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n const int mod=1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n // vector<vector<int>> dp(n+1,vector<int>(1001,0));\n int x=0;\n for(auto xx: nums) x=max(xx,x);\n\n vector<int> dp(x+1,0);\n vector<int> curr(x+1,...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n long long n = nums.size(), dp[2001][1001], mod = 1e9 + 7; memset(dp, 0, sizeof(dp));\n for ( int j = 0; j<1001; j++ ) dp[n][j] = 1;\n for ( i...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "/********************************************\n * author : Jie Chen (4th Year CS)\n * school : Rochester Institute of Technology\n * created: 08.10.2024 21:54:38\n*********************************************/\n\nusing i64 = long long;\n\n// Credit: Jiangly\ntemplate<class T>\nconstexpr T power(T a, i64 b)...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int n,m;\n const int MOD = 1e9+7;\n int countOfPairs(vector<int>& nums) {\n n = nums.size();\n m = 2001;\n \n vector<long long> dp(m,1);\n for(int ind{n-1}; ind>=0; ind--){\n //Stores the current states value:\n v...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "typedef long long ll;\nconst ll MOD = (ll)(1e9 + 7);\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<ll> ans(nums[0] + 1, 1LL);\n for (int i = 1; i < nums.size(); i++) {\n vector<ll> cs = ans;\n for (int j = 1; j < ans.size(); j++)\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n using ll=long long;\n ll mod=1e9+7;\n // ll dp[2002][1002][2];\n // ll solve(ll i, ll n, ll diff, ll flag, vector<int>&nums){\n // if(i>=n){\n // return 1*1ll;\n // }\n // if(dp[i][abs(diff)][flag]!=-1){\n // ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "int mod=1e9+7;\n// int solve(int i,int last,vector<int>& nums,vector<vector<int>>&dp)\n// {\n// if(i==nums.size())\n// return 1;\n// if(dp[i][last]!=-1)return dp[i][last];\n\n// long long ways=0; \n// int last2=1e9+9;\n// if(i>0)\n// last2=nums[i-1]-last;\n\n// for(int j=las...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <vector>\n#include <iostream>\n\nusing namespace std;\n\nconst int MOD = 1e9 + 7;\n\nclass Solution {\n int res=0;\n int rec(vector<int>& nums,vector<vector<int>>& dp,int ind, int prev1,int prev2){\n if(nums.size()==ind){\n res++;\n return 1;\n }\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <vector>\n#include <iostream>\n\nusing namespace std;\n\nconst int MOD = 1e9 + 7;\n\nclass Solution {\n int res=0;\n int rec(vector<int>& nums,vector<vector<int>>& dp,int ind, int prev1,int prev2){\n if(nums.size()==ind){\n res++;\n return 1;\n }\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<vector<optional<long long>>> dp(nums.size() + 1, vector<optional<long long>>(1001));\n const int md = 1e9 + 7;\n const auto solve = [&](auto&& self, int i, int prevArr2) -> long long {\n if (prevAr...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int mod = 1e9 + 7;\n if (n==0) return nums[0]+1;\n vector <vector <long long> > dp(n);\n vector <vector <long long> > preSum(n);\n for (int i=0; i<n; i++)\n {\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\n const int M = 1000000007;\n \n void add(int &x, int y) {\n if ((x += y) >= M) {\n x -= M;\n }\n }\n \n void dec(int &x, int y) {\n if ((x -= y) < 0) {\n x += M;\n }\n }\npublic:\n int countOfPairs(vector<int>& num...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\n\n int add(int a, int b)\n {\n int m = 1e9 + 7;\n return ((a % m) + (b % m)) % m;\n }\n\n int sub(int a, int b)\n {\n int m = 1e9 + 7;\n return (a - b + m) % m;\n }\n\npublic:\n int countOfPairs(vector<int>& nums) {\n\n int m = 1e9 +...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define vi vector<int>\n#define vvi vector<vector<int>>\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int M = 1e9+7;\n int n = nums.size();\n // dp[i] :: arr1[i].\n // vvi dp(1005, vi(n, 0));\n vi pdp(1005, 0);\n vi cdp(1005, 0);\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int MOD = 1e9 + 7;\n vector<int> prev(1001);\n vector<vector<int>> pref(2, vector<int>(1002));\n int n = nums.size();\n for (int i = 0; i <= nums[n - 1]; ++i)\n prev[i] = 1;\n f...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int mod = 1e9 + 7;\n vector<vector<int>> dp(n + 10, vector<int>(1010));\n vector<int> a(n + 10);\n for (int i = 1; i <= n; ++i) a[i] = nums[i - 1];\n vector<int> sum(1010)...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n int mod=1e9+7;\n vector<int>a;\n vector<vector<int>>dp(n+1,vector<int>(1001,0));\n a.push_back(0);\n for(auto i:nums) a.push_back(i);\n for(int i=0;i<=a[1];i++) dp[...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& arr) {\n int n = arr.size();\n const int m = 1000;\n const long long mod = 1e9 + 7;\n vector<vector<long long>> dp(n, vector<long long>(m + 800));\n dp[0][0] = 1;\n for (int i = 1; i <= arr[0]; i++) dp[0]...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "const int MOD = 1e9 + 7;\n\nclass Solution {\n int dp[2001][1001]; \n\n int helper(int ind, int parent1, vector<int>& arr) {\n int n = arr.size();\n if (ind == n) return 1;\n\n if (dp[ind][parent1] != -1) return dp[ind][parent1];\n\n int cnt = 0;\n for (int i = par...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int dp[2001][1002];\n int solve(int i, int aval, vector<int>&nums){\n int n=nums.size();\n if(i>=n)return 1;\n if(dp[i][aval+1]!=-1)return dp[i][aval+1];\n\n int ans=0;\n for(int k=aval;k<=nums[i];k++){\n in...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "using ll = long long;\nconstexpr int mod = 1e9 + 7;\n\nstruct BIT {\n vector<int> sum;\n BIT(int n) : sum(n + 1) {}\n \n BIT(const vector<int>& v) {\n sum = vector<int>(v.size() + 1);\n for (int i = 0; i < v.size(); ++i)\n update(i + 1, v[i]);\n }\n \n int lowb...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "const int MOD=1E9+7;\n\nint memo_sum[2010][1010];\nint in2[2010][1010];\nint id;\nclass Solution {\npublic:\n vector<int>nums;\n \n int sum(int p,int start,int end,vector<vector<int>> &dp) {\n \n if (start>end) return 0;\n if (start==end) return dp[p+1][start];\n if (in...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> dp(n+1,vector<int>(2001,0));\n for(int i=0;i<=2000;i++) dp[n][i]=1;\n int mod=1e9+7;\n\n for(int i=n-1;i>=0;i--){\n vector<long long> prefix(2001);...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n const int M=1e9+7;\n const int N = 1005;\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n vector<int> dp(N, 1); // dp[i+1]\n \n // return solve(0,nums,n,0,dp);\n\n for(int i=n-1;i>=0;i--){\n vector<int> new_d...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
2
{ "code": "class Solution {\npublic:\n const int M=1e9+7;\n const int N = 1005;\n \n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n vector<int> prev(N, 1); // prev[i+1] i==n condition return 1\n \n for(int i=n-1;i>=0;i--){\n vector<int> cur (N,0);\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "\nconst int MOD = 1e9 + 7;\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> dp(n, vector<int>(1001, 0)), acc = dp;\n for (int i = 0; i <= 1000; i++){\n if (i <= nums[0]) dp[0][i] = 1;\n acc[0][i] ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\nprivate:\n int mod = 1e9+7;\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<vector<long>> dp(nums.size(), vector<long>(1001, 0));\n \n for (int j = 0; j <= nums[0]; ++j) {\n dp[0][j] = 1;\n }\n for (int i = 1; i < nums.size(); ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<vector<long long>> dp (nums.size(), vector<long long> (1001));\n for (int i = 0; i <= nums[0]; i++)\n dp[0][i] = 1;\n\n for (int i = 1; i < nums.size(); i++) {\n vector<long long> prefix...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int MAX = 1000;\n vector<vector<long long>> dp(nums.size(), vector<long long> (MAX+1, 0));\n for (int i = 0; i <= nums[0]; i++) dp[0][i] = 1;\n for (int i = 1; i < nums.size(); i++) {\n \n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int mod = 1e9 + 7;\n vector<vector<int>> dp(n + 1, vector<int>(2002, 0)); // Initialize dp with 0\n vector<long> prefix(2002, 0); // Initialize prefix with 0\n \n // Base ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n /*\n for each i, split nums[i] into 2\n dp? \n dp[i][x] = number of choices splitting nums[i] at x;\n\n */\n typedef long long ll;\n ll M = 1e9+7;\n ll add(ll a, ll b){\n return ((a%M)+(b%M))%M;\n }\n int countOfPairs(vector<int>& nums) {\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n ll dp[2003][1001];\n ll mod=1e9+7;\n // ll solve(int i,int pa,vector<int>& nums){\n // ll n=nums.size(),cnt=0;\n // if(i>=n) return 1;\n // if(dp[i][pa]!=-1) return dp[i][pa];\n\n // for(int val=pa;val<=nums[i];val++){\n...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<vector<long>> v;\n v.push_back({}); v.push_back({});\n long m = 1e9+7;\n for (int i = 0; i <= nums[0]; i++){\n v[0].push_back(i+1);\n }\n for (int i = 1; i < nums.size(); i++) ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n\n long long helper(int indx, int prev,vector<int>& nums, vector<vector<long long>>&dp){\n\n if(indx>=nums.size()){\n return 1;\n }\n\n if(dp[indx][prev+1]!=-1){\n return dp[indx][prev+1];\n }\n\n const int mod = 1e9+7;...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n vector<vector<int>> dp(n,vector<int>(1002,0));\n for(int val=0;val<=nums[0];val++){\n dp[0][val]=1;\n }\n for(int i=1;i<n;i++){\n vector...
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>...
0
{ "code": "#include <vector>\n#include <algorithm>\n#include <iostream>\n\n#define NARUTO_PRINT std::cout <<\n#define SASUKE_INPUT std::cin >>\n#define SAKURA_VECTOR std::vector<int>\n#define KAKASHI_SIZE size_t\n#define HINATA_BEGIN begin()\n#define NEJI_END end()\n#define SHIKAMARU_RETURN return\n\nclass Solution {...
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>...
0
{ "code": "class Solution {\npublic:\nvector<int> resultsArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> result(n - k + 1, -1);\n\n for (int i = 0; i <= n - k; ++i) {\n bool isConsecutive = true;\n\n for (int j = i; j < i + k - 1; ++j) {\n if (nums[j + 1] != nu...
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>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> resultsArray;\n for (int i = 0; i <= nums.size() - k; i++) {\n bool isConsecutive = true;\n int sum = nums[i]; // Start with the first element of the current subarray\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>...
0
{ "code": "class Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(k == 1)\n return nums;\n vector<int> ans;\n int n = nums.size();\n for(int i = 0;i<=n-k;i++){\n bool flag = true;\n for(int j = i;j<i+k-1;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 int dp[100001] {};\n vector<int> ans {};\n dp[0] = 1;\n for (int i = 1; i < nums.size(); i++) {\n if (nums[i] - nums[i-1] == 1) {\n dp[i] = dp[i-1] + 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 \n vector<int> ascending(nums.size(), false);\n vector<int> ans;\n\n ascending[0] = true;\n for(int i = 1; i < nums.size(); i++)\n {\n if(nums[i - 1] + 1 == nums[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 int n = nums.size();\n vector<int> result;\n deque<int> dq;\n\n for (int i = 0; i < n; ++i) {\n // Remove elements out of the current window\n if (!dq.empty() && dq.front(...
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//SAME AS SLIDING WINDOW MAXIMUM PROBLEM\n vector<int> resultsArray(vector<int>& nums, int k) {\n deque<int> dq;\n vector<int> result;\n for (int i = 0; i < nums.size(); ++i) {\n if (!dq.empty() && dq.front() == i - k) {\n dq.pop_front();\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 deque<int>dq;\n if(k==1){\n return nums;\n }\n int n=nums.size();\n bool flag=true;\n int sum=0;\n dq.push_back(nums[0]);\n sum+=...
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 int i=0,j=1;\n vector<int> res;\n if(k==1){\n res.push_back(nums[0]);\n i++;\n }\n map<int,int> mem;\n while(j<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 deque<int> dq;\n vector<int> res;\n for(int i=0;i<nums.size();++i){\n\n if(dq.size() == k){\n dq.pop_back();\n }\n if(!dq.empty()){\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 vector<int> resultsArray(vector<int>& nums, int k) \n {\n vector<int>ans;\n deque<int>dq;\n dq.push_back(nums[0]);\n for(int i=1;i<k;i++)\n {\n if(dq.back()+1!=nums[i])\n {\n dq.clear();\n dq.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 deque<pair<int, int>> dq;\n int n = nums.size();\n vector<int> ans;\n for(int i = 0; i<n; i++){\n if(!dq.empty() && i-dq.back().second>=k)dq.pop_back();\n if(dq.empty()){\...
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 if(nums.size()==1 || k == 1) return nums;\n int s = 0;\n int cnt = 0;\n priority_queue<pair<int,int>> pq;\n for(int i =1;i<nums.size();i++){\n pq.pu...
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 if (k == 1) {\n return nums;\n }\n \n std::unordered_map<int, int> deltas;\n std::queue<int> q_deltas;\n for(int i = 1; i < k; ++i) {\n auto d = nums[i] - nu...
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 if (k == 1) {\n return nums;\n }\n \n std::unordered_map<int, int> deltas;\n std::queue<int> q_deltas;\n for(int i = 1; i < k; ++i) {\n auto d = nums[i] - nu...
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>\n#pragma GCC optimize (\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native\")\nusing namespace std;\n#define all(x) x.begin(), x.end()\n\n\nusing ull = unsigned long long;\nusing ll = long long;\n\ninline int gcd(int a,int b) { if (b==0) return...
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 if(n==1){\n return {a[0]};\n }\n if(k==1){\n return a;\n }\n vector<int> ans;\n\n list<int> dq;\n \n for(int i=0;i<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>& arr, int k) {\n int n = arr.size();\n vector<int> ans(n-k+1,-1),dp(n,0);\n unordered_map<int,int> store;\n for(int i=0;i<k;i++){\n if(store.count(arr[i]) == 0)store[arr[i]]=1;\n else store...
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> cons(nums.size());\n cons[0] = 1;\n vector<int> ans;\n vector<int>ma;\n priority_queue<pair<int,int>>pq;\n for(int i=1;i<nums.size();i++){\n if(nums[i] - 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": "int counts[1000005];\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n if (k == 1) {\n return nums;\n }\n memset(counts, 0, sizeof(counts));\n int inverses = 0, kinds = 1;\n vector <int> results;\n ++counts[nums[0]]...
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// public:\n// vector<int> resultsArray(vector<int>& nums, int k) {\n// // int n = nums.size();\n// // vector<int> results(n - k + 1, -1);\n// // for (int i = 0; i < n - k + 1; i++) {\n// // bool isconsecutive = true;\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> idx;\n int n=nums.size();\n for(int i=0;i<n-1;i++){\n if(nums[i]+1!=nums[i+1]){\n idx.push_back(i+1);\n }\n }\n vector<int> ans(n-k+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>& vec, int k) \n {\n vector<int>ans;\n multiset<int>mset;\n int cnt=0;\n for(int i=0;i<k-1;i++)\n {\n mset.insert(vec[i]);\n if(i>0&&vec[i]!=vec[i-1]+1)\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 unordered_map<int,int>mp;\n mp[0]=0;\n int e=nums[0];\n int cnt=0;\n vector<int>ans;\n for(int i=1;i<k;i++)\n {\n if(nums[i]==e+1)\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 unordered_map<int,int>mp;\n mp[0]=0;\n int e=nums[0];\n int cnt=0;\n vector<int>ans;\n for(int i=1;i<k;i++)\n {\n if(nums[i]==e+1)\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 {\nprivate:\n int power(const multiset<int>& got, const vector<int>& ps, int l, int r) {\n if (ps[r] - ps[l] != 0) {\n return -1; \n }\n int lo = *got.begin();\n int hi = *prev(got.end());\n if (hi - lo + 1 != got.size()) {\n return...
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 long long int f(long long int n){\n return (n*(n+1))/2;\n }\n\n vector<int> resultsArray(vector<int>& nums, int k){\n if(k==1)return nums;\n int sum = nums[0];\n multiset<int>MS;\n MS.insert(nums[0]);\n vector<int>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 int n=nums.size();\n vector<int> gap(n);\n\n for(int i=1;i<n;i++){\n if(nums[i]-nums[i-1]==1){\n gap[i]=0;\n }else{\n gap[i]=1;\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 map<int,int>mp;\n const int n = nums.size();\n vector<int> ans,dp(n,0);\n dp[0]=1;\n for(int i=0;i<n;++i){\n if(i){\n if(nums[i-1]<nums[i])dp[i]=1+dp[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 \n map<int, int> mp, ind;\n mp[nums[0]]++;\n\n for(int i = 1 ; i < k ; i++) {\n if(nums[i] != nums[i-1] + 1) {\n ind[i-1]++;\n }\n mp[nums[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": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace std;\nusing namespace __gnu_pbds;\ntemplate <class T>\nusing pbds =\n tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;\n// #define cerr if(false)cerr\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 int n=nums.size();\n deque<int> dq;\n map<int,int> mp;\n vector<int> ans;\n long long sum=0;\n for(int i=0;i<n;i++)\n {\n //if(nums[i]==dq.back()+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 int n=nums.size();\n deque<int> dq;\n map<int,int> mp;\n vector<int> ans;\n long long sum=0;\n for(int i=0;i<n;i++)\n {\n //if(nums[i]==dq.back()+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 // Sliding window of size k and check if it contains everything we need\n stack <int> st;\n vector <int> result;\n int n = nums.size();\n for(int i = 0; i<k; i++) {\n if(st.em...
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 <stack>\n#include <iostream>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n stack<int> q;\n \n // Iterate through the first k-1 elements to initialize the stack\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 queue<int> temp={};\n temp.push(nums[0]);\n int n = nums.size();\n for(int i=1;i<k;i++){\n if(nums[i]==nums[i-1]+1){\n temp.push(nums[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 stack<int> s;\n vector<int> res;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if(s.empty()){\n s.push(i);\n }\n else if(nums[i]>nums[s.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 int n = nums.size();\n int pre = 0;\n map<int, int> m;\n for(int i=1;i<n;i++){\n if(nums[i] != nums[i-1] + 1){\n m[pre] = i - 1;\n pre = 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 stack<int> st;\n vector<int> ans;\n int n = nums.size();\n for(int i=0;i<n;i++)\n {\n if(!st.empty() && st.top()+1 != nums[i])\n st = stack<int>();\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": "#include<bits/stdc++.h>\n\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntypedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key\n\nclass Solution {\np...
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 std::vector<std::vector<bool>> is_cons(n, std::vector<bool>(n, 0));\n\n for (int i = 0; i < n; ++i) {\n is_cons[i][i] = true;\n }\n\n for (int length = ...
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 bool ch(set<int>&st, multiset<int>&mst, int k, vector<int>&nums, int s, int en) {\n if((st.size()==mst.size()) && (nums[s]==*st.begin()) && (nums[en]==*st.rbegin()) && (nums[en]==(nums[s]+k-1))) return true;\n return false;\n }\n \n vector<int> re...
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 - k + 1);\n\n for (int i = 0; i <= n - k; i++) {\n int min_val = nums[i];\n int max_val = nums[i];\n bool is_sorted = true;\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 \n{\npublic:\n vector<int> resultsArray(vector<int>& nums, int k) \n {\n deque<int> dq;\n int n=nums.size();\n vector<int> result;\n for(int x=0; x<n; x++)\n {\n int pushval=-1;\n if(dq.empty()) \n {\n d...
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 if(k==1){\n vector<int>ans;\n for(int i=0;i+k-1<nums.size();i++){\n ans.push_back(nums[i]);\n }\n return ans;\n }\n set<int>st;\n mult...
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 sorted(vector<int>& v,int i,int j)\n {\n for(int k = i;k<j;k++)\n {\n if(v[k] > v[k+1])\n {\n return false;\n }\n }\n\n return true;\n }\n\n bool consecutive(vector<int> v, int i,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": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef pair<int,int> pii;\ntypedef pair<double, double> pdd;\n#define pb push_back\n#define mp make_pair\n#define fs first\n#define sc second\n#define rep(i, from, to) for (int i = from; i < (to); ++i)\n#define...
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 maxElement(set<int> &Set){\n return *Set.rbegin();\n }\n vector<int> resultsArray(vector<int>& nums, int k) {\n if(k == 1)return nums;\n vector<int> ans;\n int currMax = 0, prevMax = 0;\n \n int n = nums.size();\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 stack<int> stk;\n vector<int> result;\n for (int i = 0; i < k; i++) {\n if (!stk.empty() && stk.top() == nums[i] - 1) {\n stk.push(nums[i]);\n } else {\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 set<pair<int, int>> set;\n map<int, list<int>> map;\n for(int i = 0; i < k; i++){\n if(i + 1 < k && nums[i + 1] != nums[i] + 1 && k != 1) set.insert({i, i + 1});\n map[nums[i]].em...
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 set<pair<int, int>> set; // contains not consecutive pairs.\n map<int, list<int>> map; // to check ascending order\n for(int i = 0; i < k; i++){\n if(i + 1 < k && nums[i + 1] != nums[i] + 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 bool issorted(vector<int>& nums, int i, int j) {\n for (int idx = i; idx < j; idx++) {\n if (nums[idx] >= nums[idx + 1])\n return false;\n }\n return true;\n }\n bool iscons(vector<int> nums, int i, int j, int k){\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 if(k==1)\n {\n return nums;\n }\n int n=nums.size();\n int i=1;\n string temp;\n for( i=1;i<k;i++)\n {\n if(nums[i]==nums[i-1]+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> v(nums.size()-k+1,-1);\n for(int i=0;i<=nums.size()-k;i++)\n {\n int f=1;\n vector<int>p(nums.begin()+i,nums.begin()+i+k);\n \n for(int j=1;j<k;...
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 issorted(vector<int>& nums){\n int n=nums.size();\n for(int i=1;i<n;i++){\n if(nums[i]!=nums[i-1] + 1){\n return false;\n }\n }\n \n return true;\n}\n vector<int> resultsArray(vector<int>& nums, int k) {\n int n=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": "class Solution {\npublic:\n bool isConsecutive(const vector<int>& subarray) {\n int minVal = subarray[0];\n int maxVal = subarray[0];\n for (int i=1;i<subarray.size();i++) {\n if(subarray[i]-subarray[i-1]!=1){\n return false;\n }\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 int n = nums.size();\n if(k==1) return nums;\n vector<int> v(n - k + 1, -1);\n for (int i = 0; i < n - k + 1; i++) {\n vector<int> sub(nums.begin() + i , nums.begin() + i +k );\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>& nums,int i,int j){\n vector<int> temp(nums.begin()+i,nums.begin()+j+1);\n\n for(int k=0;k<temp.size()-1;k++){\n if(temp[k]+1!=temp[k+1]){\n return -1;\n }\n }\n\n return temp.back();\n }\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 int solve(vector<int>& nums,int i,int j){\n vector<int> temp(nums.begin()+i,nums.begin()+j+1);\n\n for(int k=0;k<temp.size()-1;k++){\n if(temp[k]+1!=temp[k+1]){\n return -1;\n }\n }\n\n return temp.back();\n }\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 vector<int> resultsArray(vector<int>& nums, int k) {\n vector<int> ans;\n \n for (int i = 0; i <= nums.size() - k; i++) {\n vector<int> subarray(nums.begin() + i, nums.begin() + i + k);\n bool isSorted = true;\n bool isCon...
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(const 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(const vector<int>& arr) {\...