id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,456 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "\nclass Solution {\npublic:\n vector<int> nums;\n int k;\n int n;\n vector<vector<vector<int>>> dp;\n int solve(int previdx, int curridx, int left) {\n if (curridx == nums.size()) {\n return 0;\n }\n if (dp[previdx][curridx][left] != -1) {\n return ... |
3,456 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n \n vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(n+1, vector<int> (k+1,0)));\n\n for(int index=n-1;index>=0;index--){\n for(int prevIndex=index-1;prevIndex>=... |
3,456 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int fun(vector<int>& nums, int k,int i,int prev,vector<vector<vector<int>>>&dp){\n if(i>=nums.size()){\n return 0;\n }\n if(dp[i][prev+1][k]!=-1){\n return dp[i][prev+1][k];\n }\n int a=0;\n if(prev==-1){\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n \n int maximumLength(vector<int>& arr, int k) {\n int n=arr.size();\n int vis[5005][55];\n memset(vis,-1,sizeof(vis));\n unordered_map<int,int>last_seen;\n vector<int>longestSoFar(k+1,0);\n vis[0][0]=1;\n last_seen[arr[0]]=0... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int result = 0, max_dp[51] = {}, dp[5000][51] = {};\n std::unordered_map<int, int> prev;\n for (int i = static_cast<int>(nums.size()) - 1; i >= 0; --i)\n {\n auto it = prev.find(nums[i]);\n... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n\n int dp[5001][51][2][2];\n \n int solve(int ind, bool knotreq, bool isst, int k, vector<int>& nums, vector<int>& nxtsame) {\n\n if(ind==nums.size())\n return 0;\n\n if(dp[ind][k][knotreq][isst]!=-1)\n return dp[ind][k][knotreq][isst];\n\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n \n int n=nums.size(),ans=1;\n unordered_map<int,int>ele;\n vector<int>nuer(n,n),ner(n,n);\n vector<vector<int>>dp(2,vector<int>(n,1)),track(2,vector<int>(n));\n \n for(int i=n-1;i... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution\n{\npublic:\n int dp[5001][2][51];\n int solve(int i, int count, bool same, vector<int> &nums, unordered_map<int, vector<int>> &mp)\n {\n if (i >= nums.size())\n return 0;\n if (dp[i][same][count] != -1)\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n unordered_set<int> elements;\n\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n // encode\n int m = 0;\n unordered_map<int, int> mp;\n for(int x : nums){\n if(mp.find(x) == mp.end()){\n mp... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n unordered_set<int> elements;\n\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n // encode\n int m = 0;\n unordered_map<int, int> mp;\n for(int x : nums){\n if(mp.find(x) == mp.end()){\n mp... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "namespace atcoder {\n\nnamespace internal {\n\n#if __cplusplus >= 202002L\n\nusing std::bit_ceil;\n\n#else\n\n// @return same with std::bit::bit_ceil\nunsigned int bit_ceil(unsigned int n) {\n unsigned int x = 1;\n while (x < (unsigned int)(n)) x *= 2;\n return x;\n}\n\n#endif\n\n// @param n `1 <=... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int idx = 0;\n unordered_map<int,int> mp;\n for (int &x : nums) {\n auto it = mp.find(x);\n if (it == mp.end()) {\n mp[x] = idx;\n x = idx++;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> dp(k+1, vector<int>(n, 0));\n unordered_map<int, int> lastSeen;\n vector<int> longest(k+1, 0);\n\n dp[0][0] = 1;\n lastSeen[nums[0]] = 0;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> dp(n);\n unordered_map<int, int> mp;\n for (int i = n - 1; ~i; --i) {\n mp[nums[i]]++;\n dp[i] = mp[nums[i]];\n }\n\n for (int i ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int ans=1,n=nums.size();\n vector<vector<int>>dp(n,vector<int>(k+1,1));\n vector<int>prevsame(n,-1);\n vector<int>prevdiff(n,-1);\n vector<int> dp1(k+1,1);\n for(int i=0;i<n;i++){\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 0 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int ans=1,n=nums.size();\n vector<vector<int>>dp(n,vector<int>(k+1,1));\n vector<int>prevsame(n,-1);\n vector<int>prevdiff(n,-1);\n vector<int> dp1(k+1,1);\n for(int i=0;i<n;i++){\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n if(!n)\n return 0;\n int ret = 1;\n unordered_map<int,int>index;\n vector<int>max_length(k+1, 0);\n vector<vector<int>>dp(n, vector<int>(k+1, 0));\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) \n {\n\n\n vector<int>longest(k+1,0);\n\n unordered_map<int,int>whr;\n\n vector<vector<int>>dp(nums.size(),vector<int>(k+1,0));\n\n\n dp[0][0]=1;\n\n whr[nums[0]]=0;\n\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int m = nums.size();\n vector<vector<int>> dp(m, vector<int>(k + 1, 1));\n vector<int> zk(k + 1, 0);\n int ans = 0;\n unordered_map<int, int> hm;\n for (int i = 0; i < m; ++i) {\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int n;\n int maximumLength(vector<int>& nums, int k) {\n n = nums.size() ;\n map<int, vector<int>> m ;\n for( int i = 0 ; i < n ; i++ ) m[nums[i]].push_back( i ) ;\n vector<vector<int>> dimpi ( n , vector<int> (k+1));\n vector<int> maxi... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size();\n unordered_map<int,vector<int>>m;\n vector<int>v(k+1,0);\n for(int i=n-1;i>=0;i--){\n vector<int>c(k+1,0);\n c[0]=1;\n for(int j=k-1;j>=0;j--){\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size();\n unordered_map<int,vector<int>>m;\n vector<int>v(k+1,0);\n // v[0]=1;\n for(int i=n-1;i>=0;i--){\n vector<int>c(k+1,0);\n c[0]=1;\n for(int ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector<vector<int>> dp(nums.size(), vector<int>(k+1, 1));\n vector<int> mx(k+1, 0);\n unordered_map<int, vector<int>> m;\n int ans = 1;\n\n for (int i = 0; i < nums.size(); i++) {\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n= nums.size();\n int res=0;\n map<int,int>m;//to map the distinct number to indices which we can use latter\n int cnt=0;\n for(int i=0;i<nums.size();i++)\n {\n if(m.find(... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n// using namespace __gnu_pbds;\n #define vb vector<bool>\n #define ff first\n #define ss second\n #define pb push_back\n #define gout(tno) cout << \"Case #\" << tno++ <<\": \"\n #define ld long double\n #define ll long lo... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& a, int k) {\n int n=a.size() ;\n vector<vector<pair<int,int>>> dp(n , vector<pair<int,int>> (k+1)) ;\n for(int e=0 ;e<=k;e++){\n dp[n-1][e] ={1,1} ;\n }\n unordered_map<int, vector<int>> val_indx ;\n... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> dp(k + 1, vector<int>(n));\n vector<deque<pair<int,int>>> best(k + 1);\n unordered_map<int, vector<int>> mp;\n for(int i = 0 ; i < n; ++i){\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n \n\n\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size();\n vector<vector<int>>dp(n,vector<int>(k+1,0));\n\n vector<int>prev(k+1,0);\n for(int i=0;i<=k;i++){\n dp[0][i]=1;\n prev[i]=1;\n }\n map<int,int>m;\n m... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n vector<vector<int>> dp(n, vector<int>(k+1, 0));\n vector<vector<int>> maxDp(n, vector<int>(k+1, 0));\n\n // base case\n for (int j = 0; j < k+1; j++) {\n dp[0]... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n\n vector<vector<int>> dp(n, vector<int>(k+1, 0));\n vector<vector<int>> maxLength(n, vector<int>(k+1, 0));\n\n // base case\n for (int j = 0; j < k+1; j++) {\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n\n vector<vector<int>> dp(n, vector<int>(k+1, 0));\n vector<vector<int>> maxVal(n, vector<int>(k+1, 0));\n\n // base case\n for (int j = 0; j < k+1; j++) {\n dp... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = 0;\n vector <vector <int>> pickdp(n+1,vector <int> (k+1,0));\n vector <vector <int>> noPickdp(n+1,vector <int> (k+1,0));\n map <int,int> lastEqual;\n for... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n // If k is large, we pigeonhole the maximum length\n if (k >= nums.size()-1){ \n return nums.size();\n }\n\n // Create our variables to help us calculate\n // Map to store last locatio... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int, int> dp;\n vector<int> prevMax(n);\n vector<int> curMax(n);\n\n for(int i=0; i<=k; i++) {\n for(int j=n-1; j>=0; j--) {\n dp[... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n unordered_map<int, int> pre; // the previous index of same number\n\t\tint n = nums.size();\n\t\tvector<vector<vector<int>>> dp(n, vector<vector<int>>(2, vector<int>(k+1, 0)));\n\t\tdp[0][1][0] = 1; pre[nums[0]] = 0;\n\t\... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n\n int fn(int i, int W, bool issame, vector<int>& nums, unordered_map<int, vector<int>>& mp, vector<vector<vector<int>>>& dp) {\n\n if (i < 0) return 0; // Base case: if we go before the first element, return 0\n if (dp[i][issame][W] != -1) return dp[i][issame][... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n // Recursive function with memoization\n int solve(int i, int W, bool issame, vector<int>& nums, unordered_map<int, vector<int>>& mp, vector<vector<vector<int>>>& dp) {\n // Base case: if we reach the end of nums, return 0\n if (i >= nums.size()) return 0;\n\... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class segtree {\npublic:\n struct node {\n // don't forget to set default value (used for leaves)\n // not necessarily neutral element!\n int tag = 0, mx = 0;\n\n void apply(int l, int r, int v) {\n tag = v;\n mx = (r - l + 1) * v;\n }\n };\n\n... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 1 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size();\n vector<vector<int>> dp(k+1,vector<int>(n,1));\n unordered_map<int,int> mp;\n for(int i=n-1;i>=0;i--){\n dp[0][i]=max(1,mp[nums[i]]+1);\n mp[nums[i]]++;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector<vector<int>> dp(k+1,vector<int>(nums.size(),0));\n unordered_map<int,int> mp;\n vector<int> imax(nums.size(),0); // store the maximum value for even rows\n vector<int> imax2(nums.size(),0);\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n // int n=int(nums.size());\n // vector<vector<int>> dp(n,vector<int>(k+1,INT_MIN));\n // dp[0][0]=1;\n // int res=1;\n // for (int i=1; i<n; ++i) {\n // dp[i][0]=1;\n // f... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector <pair<int,unordered_map<int,int>>> dp(k+1);int ans=0;\n for(int i=0;i<nums.size();i++){\n for(int j=min(k,i);j>=0;j--){\n int prev=-1;int curr=-1;\n if(j!=0)\n prev=dp[j-1... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector <pair<int,unordered_map<int,int>>> dp(k+1);int ans=0;\n for(int i=0;i<nums.size();i++){\n for(int j=min(k,i);j>=0;j--){\n int prev=-1;int curr=-1;\n if(j)\n prev=dp[j-1].f... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector <pair<int,unordered_map<int,int>>> dp(k+1);int ans=0;\n for(int i=0;i<nums.size();i++){\n for(int j=min(k,i);j>=0;j--){\n int prev=-1;int curr=-1;\n if(j!=0)\n prev=dp[j-1... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "#define ll long long\n#define pb push_back\nclass Solution {\npublic:\n ll f(ll index,ll val,vector<int>& nums,vector<vector<ll>>& dp,ll n,ll k, vector<ll>& next){\n\n if(dp[index][val]!=-1)return dp[index][val];\n if(index==n){\n return dp[index][val]=0;\n }\n if(... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "//I should learn to use iterative dp as soon as possible\n//This was a very good question\n//Used xtra space but its fine\n\n#define ll long long\n#define pb push_back\nclass Solution {\npublic:\n\n int maximumLength(vector<int>& nums, int k) {\n ll n = nums.size();\n vector<vector<ll>>dp(... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n= nums.size();\n unordered_map<int,unordered_map<int,int>>dp;\n vector<int>max_val(k+1,0);\n\n for(int i=0;i<n;i++){\n for(int rem=k;rem>=0;rem--){\n dp[nums[i]][rem] = ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n /*int f(int idx,int k,int prev,vector<int>& nums,vector<vector<vector<int>>>& dp)\n {\n if(k<0)return INT_MIN;\n if(idx==nums.size())return 0;\n\n if(dp[idx][k][prev+1]!=-1)return dp[idx][k][prev+1];\n\n int not_take = f(idx+1,k,prev,nums,dp);\n... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n unordered_map<int,unordered_map<int,int>> dp;\n vector<int> maxdp(k+1, 0);\n\n for(int i = 0 ;i< nums.size();i++){ \n for(int j = k... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n unordered_set<int> elements;\n\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n for(int x : nums){\n elements.insert(x);\n }\n\n // dp\n unordered_map<int, unordered_map<int, int>> dp; // ends[x][k] = le... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n map<int,int>mp[5005];\n int prev[5005];\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size(),ans=1;\n for(int i=0;i<n;i++){\n for(int j=0;j<=k;j++){\n mp[j][nums[i]]+=1;\n if(j)mp[j][nums[i]]=max(mp[j... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "class Solution {\npublic:\n\tint maximumLength(vector<int>& nums, int k) {\n\t\tvector<pair<int, int>> fixedNums{ make_pair(nums[0],1) };\n\t\tfor (int i = 1; i < nums.size(); ++i)\n\t\t{\n\n\t\t\tif (nums[i] == fixedNums.back().first)\n\t\t\t{\n\t\t\t\tfixedNums.back().second++;\n\t\t\t}\n\t\t\telse\n\t\t... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 2 | {
"code": "using i32 = int;\nusing i64 = long long;\nclass Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n i32 n = nums.size();\n vector <map <i32, i32>> dp (k + 1);\n vector <i32> maxi (k + 1);\n i32 res = 0;\n for (i32 i = 0; i < n; ++i) {\n for (i32 cnt = k;... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n map <int,map<int,int>> dp;\n vector<int> rem_k(k+1,0);\n int ans = 1;\n for(int i=n-1;i>=0;i--){\n for(int j=k;j>=0;j--){\n dp[nums[i]][j] = max... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector<unordered_map<int, int>> dp(k + 1);\n vector<int> res(k + 1);\n for (auto x : nums) {\n vector<int> tmp = res;\n for (int i = 0; i <= k; i++) {\n dp[i][x] = max(dp... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(std::vector<int>& nums, int k) {\n int n = nums.size();\n if (n == 0) \n return 0;\n\n vector<vector<int>> dp(n, vector<int>(k + 1, 0));\n for (int i = 0; i < n; ++i) \n dp[i][0] = 1;\n\n int res = 1;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(std::vector<int>& nums, int k) {\n int n = nums.size();\n if (n == 0) return 0;\n\n std::vector<std::vector<int>> dp(n, std::vector<int>(k + 1, 0));\n for (int i = 0; i < n; ++i) \n dp[i][0] = 1;\n\n int res = 1;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution\n{\npublic:\n int maximumLength(vector<int>& nums, int k)\n {\n int n = nums.size();\n std::vector<std::vector<int>> dp(n + 1, std::vector<int>(k + 1, 0));\n\n /*\n [x x x x x x] i\n store the max value before i\n */\n int result = 1;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n \n vector<pair<int, int>> vec;\n for(int i = 0; i < n;) {\n int curr = nums[i], cnt = 0;\n while(i < n && curr == nums[i]) {\n i++, cnt++;\n... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int N = nums.size();\n vector<vector<int>> dp(k+1, vector<int>(N, 0));\n \n map<int, int> prev;\n int change = 0;\n \n for (int i = 0; i <= k; i++) {\n prev.clear();\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\n int dfs(vector<int>& nums, int idx, int k) {\n int cnt = 0;\n if(k < 0) return 0;\n if(idx == nums.size()) return 1;\n \n for(int j=idx+1; j<nums.size(); ++j) {\n if(nums[idx] == nums[j]) {\n cnt = max(cnt, dfs(nums, j, k));... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "/*\n\n* observations:\n* f[i][j]: max len of subsequence where there is j difference\n in nums[:i], with nums[i] being the last element.\nf[0][0]: 1.\nf[i][0]: go through previous numbers and add 1 to the largest.\n\n* f[i][j]: \neither it does not add a difference.\nor\nfind the longest in f[:(i-1)][j-... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "/*\n\n* observations:\n* f[i][j]: max len of subsequence where there is j difference\n in nums[:i], with nums[i] being the last element.\nf[0][0]: 1.\nf[i][0]: go through previous numbers and add 1 to the largest.\n\n* f[i][j]: \neither it does not add a difference.\nor\nfind the longest in f[:(i-1)][j-... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\n\npublic:\n \n int maximumLength(vector<int>& nums, int k) {\n \n map<pair<int, int>, int> dp;\n \n vector<int> dpOthers(k+1, 0);\n \n for (int i=0; i<nums.size(); i++) {\n vector<int> copy(dpOthers.begin(), dpOthers.end());\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int maximumLength(vector<int>& nums, int k) {\n dp.clear();\n dp.assign((int)nums.size(), vector<int>(k+1, -1));\n\n for(int j=0; j<=k; j++){\n map<int, int>same_val_best;\n int max_dp_x_j_1 = 0; \n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector<vector<int>>dp(nums.size(),vector<int>(k+1,-1));\n //dp[i][j]\n int finalMaxLength=0;\n for(int j=0;j<=k;j++){\n map<int,int>same;\n int prevj=0;\n for(int i=0;... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int inf = -1e9;\n int n = nums.size();\n vector<vector<int>> dp(n + 1, vector<int>(k + 1, inf));\n map<pair<int, int>, int> prev;\n for (auto i : nums) {\n for (int kk = 0; kk <= k; ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size(), res = 0;\n vector<vector<int>> dp(n, vector<int>(k+1, 0));\n vector<int> prev(n, 0);\n for(int i=0;i<=k;i++)\n {\n map<int, int> mp;\n int maxy = 0;\n... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "typedef long long ll;\nconst ll INF = LONG_LONG_MAX - 1;\ntypedef vector<int> vi;\ntypedef vector<ll> vll;\ntypedef pair<int, int> pi;\n\n\nclass Solution {\npublic:\ntemplate <class T> class Segtree {\n\nprivate:\n\n const T DEFAULT = -INF/3; // Will overflow if T is an int\n\n\n vector<T> segtree;... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector<vector<int>> dp(nums.size(), vector<int>(k + 1, 0));\n\n for (int i = 0; i < k; i++)\n {\n dp[0][i] = 1;\n }\n\n unordered_map<int, int> count;\n\n for (int i = 0; i < ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "int dp[5005][55], v[5005];\n\nclass ST {\n\tpublic:\n\tint s, e, v;\n\tST *l, *r;\n\tST(int s, int e) {\n\t\tthis->s = s;\n\t\tthis->e = e;\n\t\t\n\t\t//or min/max value\n\t\tv = 0;\n\t\tl = r = NULL;\n\t}\n};\n\nST *build(int s, int e) {\n\tif(s > e) {\n return NULL;\n }\n \n ST *cur = new... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int K) {\n // goal : find the longest subseq s.t. there at most k indices i make \n // subseq[i] != subseq[i+1].\n \n // 1. dp[i][k] : maximum length subseq end at i with k indices \n // ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class SEG{\npublic:\n int n;\n vector<int>t,a;\n void init(int sz,vector<int>b){\n a=b;\n n=sz;\n t.resize(4*n);\n built(0,0,n-1);\n }\n void built(int v,int tl,int tr){\n if(tl==tr){\n t[v]=a[tl];\n }\n else{\n int tm=(t... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n // int fun(int i, int k, vector<int>& nums, vector<vector<int>> &dp){\n // if(dp[i][k] != -1){\n // return dp[i][k];\n // }\n\n // int maxLen=1;\n // for(int j=0; j<i; j++){\n // if(nums[j] == nums[i]){\n // int... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size();\n vector<vector<int>> dp(n,vector<int> (k+1,1));\n vector<map<int,int>> v(k+1);\n vector<int> mx(k+1);\n for(int i=n-1;i>=0;i--){\n vector<int> temp=mx;\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> vcnt;\n int icnt[n];\n for (int i = n-1; i >= 0; i--) {\n icnt[i] = vcnt[nums[i]]++;\n }\n \n int dp[5000] = {};\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int K) {\n // goal : find the longest subseq s.t. there at most k indices i make \n // subseq[i] != subseq[i+1].\n \n // 1. dp[i][k] : maximum length subseq end at i with k indices \n // ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int K) {\n // goal : find the longest subseq s.t. there at most k indices i make \n // subseq[i] != subseq[i+1].\n \n // 1. dp[i][k] : maximum length subseq end at i with k indices \n // ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int K) {\n // goal : find the longest subseq s.t. there at most k indices i make \n // subseq[i] != subseq[i+1].\n \n // 1. dp[i][k] : maximum length subseq end at i with k indices \n // ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& v, int k) \n { \n int n=v.size();\n vector<vector<int>>dp(k+1,vector<int>(n,1));\n map<int,int>mp;\n for(int i=n-1;i>=0;i--)\n { dp[0][i]=max(1,1+mp[v[i]]);\n mp[v[i]]++;\n }\n for... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n=nums.size();\n vector<vector<int>>dp(k+1,vector<int>(n,1));//\n\n //dp[i][j]=length of the good subsequence starting from j and having i mismatches.\n map<int,int>mp;\n for(int i=n-1;i>=0... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> vcnt;\n unordered_map<int,int> icnt;\n for (int i = n-1; i >= 0; i--) {\n icnt[i] = vcnt[nums[i]]++;\n }\n \n int dp[5000]... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> vcnt;\n unordered_map<int,int> icnt;\n unordered_map<int,vector<int>> vis;\n for (int i = n-1; i >= 0; i--) {\n icnt[i] = vcnt[nums[i]]+... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> vcnt;\n unordered_map<int,int> icnt;\n unordered_map<int,vector<int>> vis;\n for (int i = n-1; i >= 0; i--) {\n icnt[i] = vcnt[nums[i]]+... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n //dp[i][x] -> ith index par end hone wala max length ka subsequence such that we can perform atmost x operations(remember we will always take the ith element)\n int n=nums.size();\n ... |
3,452 | <p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <cod... | 3 | {
"code": "const int N = 5010, INF = 0x3f3f3f3f;\n\nclass SegmentTree {\npublic:\n struct Info {\n int l, r, v;\n Info() {}\n Info(int left, int right, int val): l(left), r(right), v(val) {}\n } seg[N<<2];\n\n explicit SegmentTree() {}\n\n void build(int u, int l, int r) {\n if... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 0 | {
"code": "class Solution {\n const int W = 11;\n unsigned long long hash(const string &s) {\n unsigned long long r = 0;\n for (char c : s) {\n r = r * W + c;\n }\n return r;\n }\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n ... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 0 | {
"code": "class Solution {\n const int W = 11;\n unsigned int hash(const string &s) {\n unsigned int r = 0;\n for (char c : s) {\n r = r * W + c;\n }\n return r;\n }\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n unordere... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 0 | {
"code": "class Solution {\n const int W = 17;\n unsigned int hash(const string &s) {\n unsigned int r = 0;\n for (char c : s) {\n r = r * W + c;\n }\n return r;\n }\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n unordere... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 0 | {
"code": "class Solution {\n const int W = 101;\n unsigned long long hash(const string &s) {\n unsigned long long r = 0;\n for (char c : s) {\n r = r * W + c;\n }\n return r;\n }\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n ... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 1 | {
"code": "class Solution {\n const int W = 101;\n unsigned long long hash(const string &s) {\n unsigned long long r = 0;\n for (char c : s) {\n r = r * W + c;\n }\n return r;\n }\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n ... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 1 | {
"code": "class Solution {\n const int W = 59;\n unsigned int hash(const string &s) {\n unsigned int r = 0;\n for (char c : s) {\n r = r * W + c;\n }\n return r;\n }\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n unordere... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 1 | {
"code": "class Solution {\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n unordered_set<string> b(begin(bannedWords), end(bannedWords));\n int cnt = 0;\n for(auto& m : message) {\n if(b.count(m)) {\n if(++cnt >= 2) break;\n ... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 1 | {
"code": "class Solution {\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n assert(message.size() > 0 && message.size() <= 100000);\n assert(bannedWords.size() > 0 && bannedWords.size() <= 100000);\n for (const auto& s : bannedWords) {\n assert(s... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 2 | {
"code": "class Solution {\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bannedWords) {\n \n unordered_set<string> s;\n \n for(auto x:bannedWords)\n {\n s.insert(x);\n }\n \n int cnt=0;\n \n for(auto x:message)\... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 2 | {
"code": "class Solution {\npublic:\n bool reportSpam(std::vector<std::string>& message, std::vector<std::string>& bannedWords) {\n std::unordered_set<std::string> bannedSet(bannedWords.begin(), bannedWords.end());\n int count = 0;\n \n for (const std::string& word : message) {\n ... |
3,541 | <p>You are given an array of strings <code>message</code> and an array of strings <code>bannedWords</code>.</p>
<p>An array of words is considered <strong>spam</strong> if there are <strong>at least</strong> two words in it that <b>exactly</b> match any word in <code>bannedWords</code>.</p>
<p>Return <code>true</code... | 3 | {
"code": "class Solution {\npublic:\n bool reportSpam(vector<string>& message, vector<string>& bw) {\n set <string> st(begin(bw),end(bw));\n int ct=0;\n for(auto &s:message) {\n if(st.count(s)) ++ct;\n }\n return ct>=2?true:false;\n }\n};",
"memory": "154400"
} |
3,573 | <p>You are given two strings <code>word1</code> and <code>word2</code>.</p>
<p>A string <code>x</code> is called <strong>valid</strong> if <code>x</code> can be rearranged to have <code>word2</code> as a <span data-keyword="string-prefix">prefix</span>.</p>
<p>Return the total number of <strong>valid</strong> <span d... | 0 | {
"code": "class Solution {\npublic:\n long long validSubstringCount(string word1, string word2) {\n \n vector<int> a(26);\n vector<int> target(26);\n \n for(auto x:word2)\n {\n target[x-'a']+=1;\n }\n \n long long ans=0;\n \n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.