id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,535 | <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 n;\n int mod;\n int recur(vector<int>& nums,vector<int>&arr1,vector<int>&arr2,int ind,vector<vector<int>>& dp,int first){\n if(ind == n){\n if(arr1.size()==n && arr2.size()==n){\n return 1;\n }else{\n return... |
3,535 | <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 mod = 1e9 + 7;\n int n = nums.size(); int m = *max_element(nums.begin(), nums.end());\n long long dp[n + 1][m + 1]; // ith index & increasing value is j\n for (int i = 0; i <= n; i++)\n for (in... |
3,535 | <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 long long int mod=1e9+7;\n long long int dfs(int current, int idx, vector<int>& nums, vector<vector<long long int>>& dp){\n if(dp[current][idx]!=-1)return dp[current][idx];\n\n if(idx==(nums.size()-1))return 1;\n\n long long int ans=0;\n\n for(i... |
3,535 | <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>& v) {\n int n = v.size();\n int mod = 1e9+7;\n vector<vector<long long>> dp(n + 1, vector<long long>(51));\n for (int i = 0; i <= v[0]; i++)\n dp[0][i] = 1;\n for (int i = 1; i < n; i++) {\n ... |
3,535 | <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 long long func(int i, long long n, vector<int> &nums, vector<vector<long long> > &dp) {\n if(i >= nums.size()) {\n return 1;\n }\n if(dp[i][n] != -1){\n return dp[i][n];\n }\n long long ans = 0;\n for(int j = n; ... |
3,535 | <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 {\n long long int mod = 1e9+7;\n long long dp[52][52][2004];\n long long fun(vector<int>&nums,int n,int pre1,int pre2){\n if(n < 0) return 1;\n if(dp[pre1][pre2][n] != -1) return dp[pre1][pre2][n];\n long long ans = 0;\n for(int i=nums[n];i>... |
3,535 | <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 long int dp[2005][52][52];\n long int mod=1e9+7;\n int f(vector<int>&nums, int ind, int l, int r, int prev)\n {\n if(ind==nums.size())return 1;\n if(dp[ind][l][prev+1]!=-1)return dp[ind][l][prev+1];\n long int temp=0;\n for(int i=l;i<=r;i++)\... |
3,535 | <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(), MOD = 1e9+7;\n vector<vector<int>> dp(n+1,vector<int> (55,0)), pref(n+1,vector<int> (55,0));\n for(int j = 0; j<=nums[0]; j++){\n dp[0][j]=1;\n pref[0][j]=dp[0][j];\n ... |
3,535 | <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": "#define ll long long int\n#define ld long double\n#define pb push_back\n#define vb vector<bool>\n#define vi vector<int>\n#define vc vector<char>\n#define vvc vector<vc>\n#define vvi vector<vi>\n#define vvvi vector<vvi>\n#define vs vector<string>\n#define pii pair<int, int>\n#define vpii vector<pii>\n#defin... |
3,535 | <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 ans = 0;\n vector<int> v;\n for(int i=0; i<=50; i++) v.push_back(0);\n for(int i=0; i<=nums[0]; i++)\n {\n v[i] = 1;\n }\n for(int i=1; i<nums.size(); i++)\n {\n ... |
3,535 | <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": "typedef long long ll;\n\nclass Solution {\npublic:\n\n const ll mod = 1e9 + 7;\n ll n;\n ll memo[55][55][2005];\n bool visited[55][55][2005];\n\n ll solve(ll x, ll y, ll p, vector<int> &nums) {\n if (p == n) {\n return 1;\n }\n if (visited[x][y][p]) {\n ... |
3,535 | <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": "#include <vector>\n#include <unordered_map>\n#include <tuple>\n\nstruct State {\n int i, j, k;\n \n bool operator==(const State &other) const {\n return i == other.i && j == other.j && k == other.k;\n }\n};\n\nstruct StateHash {\n std::size_t operator()(const State &state) const {\n ... |
3,535 | <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 triple{\n public:\n int idx;\n int left1;\n int left2;\n triple(int idx,int left1,int left2){\n this->idx=idx;\n this->left1=left1;\n this->left2=left2;\n }\n\n bool operator==(const triple& b) const{\n r... |
3,535 | <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": "#include <vector>\n#include <cstring> // for memset\n\nclass Solution {\npublic:\n int countOfPairs(std::vector<int>& nums) {\n const int MOD = 1e9 + 7;\n int n = nums.size();\n int dp[n+1][101][101];\n memset(dp, -1, sizeof(dp));\n \n std::function<int(int, in... |
3,535 | <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": "#define ll long long\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n \n int n = nums.size(),i,j,k;\n const ll mod = 1e9+7;\n ll dp[n][51][51];\n ll pre[n][51][51];\n \n memset(dp,0,sizeof(dp));\n memset(pre,0,sizeof(pre));\n ... |
3,535 | <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": "#include <bits/stdc++.h>\nusing namespace std ; using namespace chrono;\n\n#define ll long long\n#define rep(i,n) for(int i=0;i<n;i++)\n#define repk(i,k,n) for(int i=k;i<n;i++)\n#define pb push_back\n#define vec vector<int>\n#define vecc vector<vector<int>>\n#defin... |
3,535 | <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;\nvector<vector<vector<int>>> dp;\n\nclass Solution {\n int f(int idx, int prev1, int prev2, vector<int>& nums) {\n if (idx == nums.size()) return 1;\n if (dp[idx][prev1][prev2] != -1) return dp[idx][prev1][prev2];\n\n int count = 0;\n for (int arr1 = ... |
3,535 | <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\n{\npublic:\n const int MOD = 1e9+7;\n int countOfPairs(vector<int> &nums)\n {\n if (nums.size() == 0)\n return 0;\n if (nums.size() == 1)\n return nums[0] + 1;\n vector<vector<int>> prev;\n for (int i = 0; i <= nums[0]; i++)\n {\n prev.push_back({i, nums[0] ... |
3,535 | <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 modulo = 1e9 + 7;\n int countOfPairs(vector<int>& nums) {\n int total = 0;\n int prev1 = -1;\n int prev2 = 51;\n vector<vector<int>> pair_counts = { {-1, 51, 1}}; // arr1, arr2, total\n for(auto& n: nums) {\n vector<vector<... |
3,535 | <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 countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<pair<int,int>>> storage(n);\n for(int i=0;i<n;i++){\n int value = nums[i];\n for(int j=0;j<=value;j++){\n storage[i].pu... |
3,535 | <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": "#define ll long long\n#define M 1000000007\nclass Solution {\n vector<ll> generatePrefixSum(vector<ll>& arr){\n int n = arr.size();\n vector<ll> ps(n, 0);\n ps[n-1] = arr[n - 1] % M;\n for(int i = n - 2; i >= 0; i--){\n ps[i] = (arr[i] + ps[i + 1]) % M;\n }\... |
3,535 | <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": "#define mod 1000000007\n#define ll long long\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n ll n = nums.size();\n \n if (n == 0) return 0;\n\n map<pair<ll, ll>, ll> dp;\n\n for (ll i = 0; i <= nums[n - 1]; ++i) {\n dp[{i, nums[n - 1] - ... |
3,535 | <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": "#define mod 1000000007\n#define ll long long\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n\n std::ios::sync_with_stdio(false);\n std::cin.tie(0);\n \n ll n = nums.size();\n \n if (n == 0) return 0;\n\n map<pair<ll, ll>, ll> dp;\n\n ... |
3,535 | <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": "#define ll long long\n#define MOD 1000000007LL\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int r = *max_element(nums.begin(),nums.end());\n vector<vector<ll>> dp(n,vector<ll>(r+1,0));\n for (int x = 0; x <= nums[0]; ++x) dp[0][x... |
3,535 | <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:\nconst int MOD = 1e9+7;\nlong long int solve (int i , int prev , vector <int>& nums , int n , vector <vector <long long int>>&dp) {\n if (i == n) return 1;\n if (dp[i][prev] != -1) return dp[i][prev];\n long long int a = 0;\n for (int j = prev; j <= nums[i]; j++) {\n ... |
3,535 | <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": "#define ll long long\n#define M 1000000007\nclass Solution {\n vector<ll> generatePrefixSum(vector<ll>& arr){\n int n = arr.size();\n vector<ll> ps(n, 0);\n ps[n-1] = arr[n - 1] % M;\n for(int i = n - 2; i >= 0; i--){\n ps[i] = (arr[i] + ps[i + 1]) % M;\n }\... |
3,535 | <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": "#define f first\n#define s second\n#define pb push_back\n#define all(x) x.begin(),x.end()\n#define sz(x) (long long)(x).size()\n#define pii pair<long long,long long>\n\nclass Solution {\nprivate:\n const int mod = 1e9 + 7;\npublic:\n long long DP(long long fir, long long idx, vector<int> &nums, vecto... |
3,535 | <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": "#define pii pair<int,pair<int,int>>\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<map<pair<int,int>,int>>mp(n);\n for(int i=0;i<=nums[n-1];i++)\n mp[n-1][{i,nums[n-1]-i}]=1;\n int mod = 1e9+7,ans = 0;\n fo... |
3,535 | <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 const int MOD = 1e9 + 7;\n \n vector<vector<int>> dp(n, vector<int>(201, 0));\n \n // Initialize dp for the first element\n for (int i = 0; i <= nums[0]; ++i) {\n ... |
3,535 | <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(const vector<int>& nums) {\n int steps = nums.size();\n int tears = 1 + *max_element(nums.begin(), nums.end());\n int mod = 1e9 + 7;\n\n vector<int64_t> eachStep(tears, 0);\n for (int i = 0; i <= nums.back(); ++i) {\n eachStep[i] = 1;\n }... |
3,535 | <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": "#include <iostream>\n#include <vector>\n#include <map>\nusing namespace std;\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int MOD = 1e9 + 7;\n int n = nums.size();\n vector<map<pair<int, int>, long long>> dp(n);\n\n for (int x = 0; x <= nums[0]... |
3,535 | <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 map<pair<long long, long long>, long long> nextStep(long long total, map<pair<long long, long long>, long long> prev) {\n map<pair<long long, long long>, long long> curr;\n for (auto& p : prev) {\n long long left = p.first.first;\n long lon... |
3,535 | <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 vector<vector<int>> dp;\n int solve(vector<int>& nums, int i, int prev) {\n if (i >= nums.size()) {\n return 1;\n }\n if (dp[i][prev] != -1) {\n return dp[i][prev];\n }\n int ans = 0;\n f... |
3,535 | <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 {\n int large = 1e9;\n int MOD=1e9+7;\n int solve(int idx,int ld, vector<vector<int>>&dp, vector<int>&nums){\n if(idx==nums.size())return 1;\n if(dp[idx][ld]!=-1)return dp[idx][ld];\n int lst1=ld,end,count=0;\n if(idx==0)end=large;\n else end = num... |
3,535 | <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 // d.resize(51,vector(51,vector(nums.size(),INT_MIN)));\n numsg = std::move(nums);\n return helper(0,numsg[0]+1,0);\n }\n vector<int> numsg;\n // vector<vector<vector<int>>> d;\n unordered_map<int,unorde... |
3,535 | <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 int;\nclass Solution {\npublic:\n \n void print(map<pair<int , int> , int>&dp){\n for (auto x : dp){\n cout <<\"[\" << x.first.first << \",\" << x.first.second << \"]\" << \"=\" << x.second << endl;\n }\n cout << \"===========================\" << ... |
3,535 | <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 countPairs(vector<vector<int>>& next, int id, vector<int>& nums){ \n if(id == -1){\n int ans = 0;\n for(int i = 0; i < next.size(); i++){\n ans = (ans % MOD + next[i][2]% MOD)%MOD;\n }\n ... |
3,535 | <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 {\npublic:\n int countOfPairs(vector<int>& nums) {\n \n int n = nums.size();\n \n vector <vector<vector<int>>> dp(n);\n map < pair<int, int>, int> mp;\n \n for(int i = 0; i <= nums[0]; i++){\n int l = ... |
3,535 | <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<vector<int>>> dp(n,vector<vector<int>>(51,vector<int>(2,0)));\n for(int i = 0;i<=nums[0];i++)\n {\n dp[0][i][0] = 1;\n }\n ... |
3,535 | <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<vector<int>>>dp(n,vector<vector<int>>(51,vector<int>(2)));\n for(int i=0; i<=nums[0]; i++)\n {\n dp[0][i][0]=nums[0]-i;\n dp[0]... |
3,535 | <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 maxn=1e9+7;\n vector<int> B;\n // vector<vector<int>>dp(50,vector<int>(2000,-1));\nlong long help(vector<int>& nums, int pre, int index, int size_of_nums,vector<vector<long long>>&dp)\n{\n if(dp[pre][index]!=-1)\n return dp[pre][index];\n if(index=... |
3,535 | <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 maxn=1e9+7;\n vector<int> B;\n // vector<vector<int>>dp(50,vector<int>(2000,-1));\nlong long help(vector<int>& nums, int pre, int index, int size_of_nums,vector<vector<long long>>&dp)\n{\n if(dp[pre][index]!=-1)\n return dp[pre][index];\n if(index=... |
3,535 | <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 maxn=1e9+7;\n vector<int> B;\n // vector<vector<int>>dp(50,vector<int>(2000,-1));\nlong long help(vector<int>& nums, int pre, int index, int size_of_nums,vector<vector<long long>>&dp)\n{\n if(dp[pre][index]!=-1)\n return dp[pre][index];\n if(index=... |
3,535 | <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 vector<vector<long long>> pairs;\n for (int j = 0; j <= nums[0]; j++) {\n pairs.push_back({j, nums[0] - j, 1});\n }\n\n for (int i = 1; i < nums.size(); i++) {\n vector<vector<long long>... |
3,535 | <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 = pow(10, 9) + 7;\n vector<vector<vector<long long>>> dp(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j <= nums[i]; j++) {\n int tmp = (i == n... |
3,535 | <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 M = 1e9 + 7;\nclass SegmentTree{\n int n;\n vector<int> Seg;\n int query(int i, int sL, int sR, int qL, int qR){\n if(sL > qR || sR < qL) return 0;\n if(sL >= qL && sR <= qR) return Seg[i];\n\n int left_sum = query(2 * i + 1, sL, (sL + sR) / 2, qL, qR);\n int ... |
3,535 | <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 map<int,int> mp;\n int MOD = 1e9+7;\n for(int i = nums.size()-1;i>=0;i--){\n map<int,int> te;\n int pre = 0;\n for(int j = 50;j>=0;j--){\n if(i == nums.size() - 1){\n ... |
3,535 | <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 long long mod = 1e9 + 7;\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<long long>> dp(2005, vector<long long>(55, 0));\n long long cnt = 0;\n for(int j = 0; j <= nums[0]; j++)\n {\n dp[0][j]... |
3,535 | <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 {\nprivate:\n const int mod = 1e9+7;\n vector<vector<long long>> dp;\n long long rec(int level, int i, vector<int> &nums){\n int n = nums.size();\n \n //pruning\n if(level==n-1){\n return 1LL;\n }\n int j = nums[level]-i;\n ... |
3,535 | <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": "typedef long long ll;\n\nclass Solution {\npublic:\n const ll MOD = 1e9 + 7;\n\n ll modadd(ll a, ll b) {\n return ((a % MOD) + (b % MOD)) % MOD;\n }\n\n int func(ll idx, ll val, ll val2, vector<int>& nums, vector<vector<ll>>& dp) {\n if (idx == nums.size()) return 1;\n ll a... |
3,535 | <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 {\nprivate:\n const int mod = 1e9+7;\n vector<vector<long long>> dp;\n long long rec(int level, int i, vector<int> &nums){\n int n = nums.size();\n \n //pruning\n if(level==n-1){\n return 1LL;\n }\n int j = nums[level]-i;\n ... |
3,535 | <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:\nconst int mod=1e9+7;\n long long helper(int ind,int prev,vector<int>&nums,vector<vector<long long>>&dp){\n if(ind<0) return 1;\n if(dp[ind][prev+1]!=-1) return dp[ind][prev+1];\n int res=0;\n \n for(int i=0;i<=nums[ind];i++){\n if(... |
3,535 | <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": "typedef long long ll;\n\nclass Solution {\npublic:\n const ll MOD = 1e9 + 7; // Modulo constant\n\n // Function to perform modular addition\n ll modadd(ll a, ll b) {\n return ((a % MOD) + (b % MOD)) % MOD;\n }\n\n // Recursive function to calculate the count of valid pairs\n int fu... |
3,535 | <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\n{\nprivate:\n long long mod = 1e9 + 7;\n unordered_map<int, unordered_map<int, int>> dp[2001];\n\npublic:\n int countOfPairs(vector<int>& nums)\n {\n int n = nums.size(); \n return dfs(nums, 0, 0, 1000);\n }\n\n long long dfs(vector<int>& nums, int i, ... |
3,535 | <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 long long int mod=1e9+7;\n long long solve(vector<int>&nums,int prev,int ind,vector<vector<long long>>&dp){\n if(ind==nums.size()){\n return 1;\n }\n if(dp[ind][prev+1]!=-1)return dp[ind][prev+1];\n long long l=0;\n for(int i=0... |
3,535 | <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 {\n int n;\n int mod = 1e9 + 7;\n vector<unordered_map<int, unordered_map<int, int>>> dp;\n int solve(vector<int>& nums, int idx, int st1, int en2) {\n if(idx == n) return 1;\n int num = nums[idx];\n \n int res = 0;\n\n if(dp[idx].count(st1) && ... |
3,535 | <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 // Memoization map: dp[i][prev_inc][prev_dec]\n unordered_map<int, unordered_map<int, unordered_map<int, int>>> dp;\n \n int countPairs(int i, int prev_inc, int prev_dec, vector<int>& nums) {\n // Base case: if we reached the end of the... |
3,535 | <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 solve(int i, int prev_inc,int prev_dec,vector<int>&nums,unordered_map<int,unordered_map<int,unordered_map<int,int>>>&dp){\n if(i==nums.size())return 1;\n int mod=1e9+7;\n if(dp[i][prev_inc].count(prev_dec))return dp[i][prev_inc][prev_dec];\n lo... |
3,535 | <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:\nunordered_map<int,unordered_map<int,unordered_map<int,int>>> dp;\nint M = 1e9+7;\n long long solveDP(int i, vector<int>& nums, int prv1 , int prv2){\n if( i == nums.size())return 1;\n if(dp.count(i) and dp[i].count(prv1) and dp[i][prv1].count(prv2))return dp[i][p... |
3,535 | <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 solve(int i, int one, int two, vector<int>& nums, unordered_map<int, unordered_map<int, unordered_map<int, int>>> &dp)\n {\n if(i==nums.size())\n return 1;\n\n if(dp[i][one].find(two)!=dp[i][one].end())\n {\n ... |
3,535 | <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 const int N = nums.size(), M = 1000000007;\n vector<unordered_map<int, unordered_map<int, int>>> cache(N);\n function<int(int, int, int)> dfs = [&](int min, int max, int i) -> int {\n if (i == N) return 1... |
3,535 | <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 unordered_map<int, unordered_map<int, unordered_map<int, int>>> dp;\n\n int f(int idx, vector<int> &nums, vector<int> &v1, vector<int> &v2) {\n if (idx == nums.size()) {\n return 1; \n }\n \n if (dp.count(idx) &&... |
3,535 | <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 md = 1e9 + 7;\n vector<int> nums;\n unordered_map<int, unordered_map<int, unordered_map<int, int>>> dp;\n\n int rec(int i, int p1, int p2) {\n if (i == nums.size()) return 1;\n if (dp.count(i) && dp[i].count(p1) && dp[i][p1].count(p2))return d... |
3,535 | <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 m = nums[0], M = 1e9 + 7;\n vector<vector<long>> dp, t;\n for(int i = 0; i <= m; i++) dp.push_back({i, m - i, 1});\n for(int i = 1; i < nums.size(); i++) {\n t = vector<vector<long>>();\n ... |
3,535 | <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 \n long long int f(long long int a,long long int b,long long int ind,vector<int> &nums,vector<vector<int>> &dp)\n {\n long long int n = nums.size();\n long long int mod = 1e9+7;\n if(ind>=n)\n {\n return 1;\n }\n if(d... |
3,535 | <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;\nclass Solution {\npublic:\n vector<int> arr;\n int solve(int prev1, int i, vector<vector<int>> &dp)\n {\n if(i >= arr.size())\n {\n return 1;\n }\n\n if(dp[prev1][i] != -1)\n {\n return dp[prev1][i];\n }\n ... |
3,535 | <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;\nclass Solution {\npublic:\n const ll MOD=1e9+7;\n ll f(ll i, int j,vector<int>& a,vector<vector<ll>>& dp){\n ll n=size(a);\n if(i>=n){\n return 1;\n }\n if(dp[i][j]!=-1){\n return dp[i][j]%MOD;\n }\n ll c{};\n ... |
3,535 | <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 long mod = 1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<long>> memo(n+1, vector<long>(2001, -1));\n return rec(nums, 0, 0, memo) % mod;\n }\n \n long rec(vector<int> &nums, int si, int lvInc, vector<vec... |
3,535 | <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 = 1000000007;\n\n long long solve(int i, int n, int pre, vector<vector<long long>> &dp, vector<int> &nums) {\n \n if(i >= n) {cout<<pre<<endl;return 1;}\n if(dp[i][pre] != -1) return dp[i][pre];\n long long ans = 0;\n for(int curr... |
3,535 | <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 long long int mod = 1000000007;\n long long int fun(int start, int arr1_prev, vector<int>& nums, vector<vector<long long int>>& dp) {\n if(start == nums.size()){\n return 1;\n }\n int prev_number = (start == 0) ? 50 : nums[start - 1];\n ... |
3,535 | <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 mod=1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n vector<int> prev(1011,0);\n for(int i=0;i<=nums[n-1];i++){\n prev[i]=1;\n }\n for(int i=1001;i>=0;i--)prev[i]=(prev[i]+prev[i+1])%mod;\n ... |
3,535 | <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 SegTree {\n vector<int> tree;\n int sz;\n\npublic:\n SegTree(int n) {\n sz = n;\n tree.assign(4 * n, 0);\n }\n\n void upd(int node, int srt, int end, int idx, int value) {\n if (srt == end) {\n tree[node] = value;\n } else {\n int mid =... |
3,535 | <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:\nint countOfPairs(vector<int>& nums) {\n int n=nums.size();\n vector<vector<long long>> dp(2050, vector<long long> (60, 0));\n for (int i=0; i<=nums[0]; i++) {\n dp[0][i]=1;\n }\n long long maxN=pow(10, 9)+7;\n\n for (int i=1; i<n; i++) {\n for (int... |
3,535 | <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 = 1000000007;\n\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n if (n == 1) return nums[0] + 1;\n\n vector<vector<int>> dp(101, vector<int>(101, 0)); // dp[cur1][cur2]\n \n // Initialize the first state\n ... |
3,535 | <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": "int count(int pos, int prev_val, vector<int> &nums, vector<vector<int>> &dp){\n if (pos==(nums.size())){\n return 1;\n }\n int MOD=1e9+7;\n int ans=0;\n if (dp[pos][prev_val]!=-2){\n return dp[pos][prev_val];\n }\n for (int curr_val=prev_val; curr_val<=nums[pos]; curr_val... |
3,535 | <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//foxed\n vector<vector<int>> dp;\n int mod= 1e9+7;\n\n int solve(int index, int lastlower, vector<int>&v)\n {\n if(index==v.size())\n return 1;\n\n if(dp[index][lastlower]!=-1)\n return dp[index][lastlower];\n\n long count=0;\n\n ... |
3,535 | <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 mod = 1e9+7;\n const int mxn = 2020;\n // const int mxn = 6;\n int mad(int a,int b){\n a += b;\n return a>=mod?a-mod:a;\n }\n int countOfPairs(vector<int>& nums) {\n vector<int> dp(mxn,0);\n for(int i = 0;i<=nums[0];i++)dp[... |
3,535 | <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 const int mod = 1e9+7;\n int n = nums.size();\n vector<vector<long long>>dp(2010,vector<long long>(1010,0LL));\n vector<long long>prefix(1010);\n for(int x=0;x<=nums[0];x++){\n dp[0][x] = 1;... |
3,535 | <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 // dp[i][j] shows number of possible monotonic pairs of len ==i with last elem as j for the non decreasing one\n //From dp[i][j], we can make transition till numbers dp[i+1][j->nums[i+1]]\n int MOD = 1000000007;\n\... |
3,535 | <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 MOD = 1e9 + 7;\n \n // Recursive function to count valid monotonic pairs\n int solve(vector<int> &nums,int prev,int ind,vector<vector<int>> &dp){\n if(ind==nums.size()) return 1;\n int cnt=0;\n if(dp[ind][prev]!=-1) return dp[ind][prev]... |
3,535 | <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 long long mod=1e9+7;\n int f(int ind,int prev,vector<int>& nums,vector<vector<int>>& dp){\n if(ind >= nums.size()) return 1;\n if(dp[ind][prev]!=-1) return dp[ind][prev];\n int c=0;\n for(int v1=prev;v1<=nums[ind];v1++){\n int v2=nums... |
3,535 | <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 MOD = 1e9 + 7;\n\n int func(vector<vector<int>>&dp,vector<int>& incArr, vector<int>& decArr, vector<int>& nums, int prev, int index, int minn) {\n int m = decArr.size();\n if(dp[index][prev]!=-1) return dp[index][prev];\n if (m == nums.size()) {\n //... |
3,535 | <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 // this function calculates state for the top-down DP that we have initialised\n int fun(int ind, int val, vector<int> &v, vector<vector<int>> &dp){\n int n = v.size();\n if(ind == n) return 1;\n\n if(dp[ind][val] != -1) return ... |
3,535 | <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 largest_ele = 2001;\n vector<vector<int>> dp (n+1, vector<int>(largest_ele));\n int mod = 1e9 + 7;\n for(int i=0; i<largest_ele; i++){\n if(i <= nums[0]){\n ... |
3,535 | <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 auto dp = vector<vector<optional<int>>>(nums.size()+1, vector<optional<int>>(1001));\n constexpr auto md = static_cast<int>(1e9+7);\n const auto solve = [&](auto&& self, const auto i, const auto prevArr2) {\n ... |
3,535 | <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 long long mod=1e9+7;\n int solve(int index,int v1,int v2,vector<int> &nums,vector<vector<vector<long long>>> &dp)\n {\n if(index==nums.size())return 1;\n if(dp[index][v1][v2]!=-1)return dp[index][v1][v2];\n long long ans=0;\n for(int i=v1;i<=... |
3,535 | <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 = 1000000007;\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<vector<long>>> dp(n, vector<vector<long>>(55, vector<long>(55, 0)));\n for(int i = 0; i <= nums[0]; ++i){\n dp[0][i][nums[0]-i] = 1;\n ... |
3,535 | <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": "#define ll long long \nconst ll mod=1e9+7;\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& v) {\n int n=v.size();\n\n vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(55,vector<ll>(55,-1)));\n auto f=[&](const auto &self,ll idx,ll prev1,ll prev2)->ll\n {\n // cout<<id... |
3,535 | <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 long long solve(vector<vector<vector<long long>>> &dp, vector<int>& nums, int ind, int mini, int maxi){\n if(ind == nums.size()) return 1;\n if(dp[ind][mini][maxi] != -1) return dp[ind][mini][maxi];\n\n long long count = 0;\n long long mod = 1e9+7;... |
3,535 | <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 long long mod = 1e9+7;\n \n long long solve(int idx, int v1, int v2 , vector<int>&values ,vector<vector<vector<long long >>>&dp){\n if (idx >= values.size()) return 1;\n long long cnt = 0;\n \n if (dp[idx][v1][v2] != -1) re... |
3,535 | <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 mod = 1e9 + 7;\n vector<vector<vector<long long>>> dp;\n\n long long solve(vector<int>& nums, int i, int n, int last1, int last2) {\n if (i >= n) {\n return 1;\n }\n if (dp[i][last1][last2] != -1) {\n return dp[i][las... |
3,535 | <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;\nclass Solution {\npublic:\n ll solve(int ind,int a,int b,vector<int>&values,vector<vector<vector<ll>>>& dp) {\n if (ind>=values.size()){\n return 1; \n } \n ll ans=0;\n ll modd=1e9+7;\n if (dp[ind][a][b]!=-1){\n return dp... |
3,535 | <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;\nclass Solution {\npublic:\n ll solve(int ind,int a,int b,vector<int>&values,vector<vector<vector<ll>>>& dp) {\n if (ind>=values.size()){\n return 1; \n } \n ll ans=0;\n ll modd=1e9+7;\n if (dp[ind][a][b]!=-1){\n return dp... |
3,535 | <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": "typedef long long ll;\nclass Solution {\npublic:\n const int MOD = 1e9 + 7;\n ll sum(ll idx,ll prev1,ll prev2,vector<int> &nums,vector<vector<vector<ll>>> &dp) {\n if(idx==nums.size()) {\n return 1;\n }\n auto &x=dp[idx][prev1][prev2];\n if(x!=-1) {\n ... |
3,535 | <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 long long mod = 1e9+7;\n long long f(vector<int>& nums,long long p1,long long p2,long long i,vector<vector<vector<long long>>>& dp){\n if(i==nums.size()){\n return 1;\n }\n if(dp[i][p1][p2]!=-1){\n return dp[i][p1][p2];\n }... |
3,535 | <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 fun(int i, vector<int> &nums, int n, int prev, int sprev, vector<vector<vector<int>>> &dp)\n {\n if(i == n)\n return 1;\n \n if(dp[i][prev][sprev] != -1)\n return dp[i][prev][sprev];\n \n long long temp = 0;\n ... |
3,535 | <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 vector<int> nums;\n int MOD = 1e9 + 7;\n vector<vector<vector<int>>> tbl;\n\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int offset = 50;\n tbl.resize(n + 1, vector<vector<int>>(51, vector<int>(101, -1)));\n\n this->num... |
3,535 | <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 const int MOD = 1e9 + 7;\n int n = nums.size();\n int maxVal = 50;\n\n // dp[x][y]: number of valid (arr1, arr2) pairs at the current index with arr1[i] = x and arr2[i] = y\n vector<vector<int>> dp(max... |
3,535 | <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 f(int ind, int prev1, int prev2, vector<int> &nums, vector<vector<vector<int>>> &dp)\n {\n int n = nums.size();\n if(ind == n)\n return 1;\n\n if(dp[ind][prev1][prev2] != -1)\n return dp[ind][prev1][pre... |
3,535 | <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 const int mod = 1e9 + 7;\n\n vector<vector<int>> initializeDP(int firstNum) {\n vector<vector<int>> dp(51, vector<int>(51, 0));\n for (int a = 0; a <= firstNum; ++a) {\n dp[a][firstNum - a] = 1;\n }\n return dp;\n }\n\n vector<... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.