id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution\n{\npublic:\n int findWinningPlayer(vector<int> &skills, int k)\n {\n int n = skills.size();\n if (k >= n - 1)\n {\n return max_element(skills.begin(), skills.end()) - skills.begin();\n }\n\n // mp{ skills, ind , wins}\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int max_num=0;\n unordered_map<int, int> mp;\n for(int i=0; i<skills.size(); i++){\n mp[skills[i]] = i;\n max_num = max(max_num, skills[i]);\n }\n \n int coun...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n \n unordered_map<int, int> mp;\n \n for(int i=0;i<skills.size();i++){\n mp[skills[i]]=i;\n }\n int maxVal=*max_element(skills.begin(), skills.end());\n \n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n typedef pair<int, int> PII; \n\n int findWinningPlayer(vector<int>& skills, int k) {\n int n = skills.size(); \n int mx = skills[0]; \n int mxi = 0; \n for(int i=1; i<n; i++){\n if(mx < skills[i]){\n mx = skills[i]; \n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n typedef pair<int, int> PII; \n\n int findWinningPlayer(vector<int>& skills, int k) {\n int n = skills.size(); \n int mx = skills[0]; \n int mxi = 0; \n for(int i=1; i<n; i++){\n if(mx < skills[i]){\n mx = skills[i]; \n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n=skills.size();\n if(k>=n-1) return max_element(skills.begin(),skills.end()) - skills.begin();\n deque<pair<int,int>> dq;\n map<int,int> mp;\n for(int i=0;i<n;i++){\n mp[s...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n=skills.size();\n if(k>=n-1) return max_element(skills.begin(),skills.end()) - skills.begin();\n deque<pair<int,int>> dq;\n map<int,int> mp;\n for(int i=0;i<n;i++){\n mp[s...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n=skills.size();\n if(k>=n-1) return max_element(skills.begin(),skills.end()) - skills.begin();\n deque<pair<int,int>> dq;\n map<int,int> mp;\n for(int i=0;i<n;i++){\n mp[s...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n=skills.size();\n if(k>=n-1) return max_element(skills.begin(),skills.end()) - skills.begin();\n deque<pair<int,int>> dq;\n map<int,int> mp;\n for(int i=0;i<n;i++){\n mp[s...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int curStreak = 0;\n int n = skills.size();\n map<int, int>initIdxs;\n for (int i = 0; i < n; i++) {\n initIdxs[skills[i]] = i;\n }\n int winnerSkill = skills[0];\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& arr, int k) {\n map<int, int> mp;\n int i = 0;\n for(auto &x: arr){\n mp[x] = i++;\n }\n int c = 0, a = arr[0];\n for(int i = 1; i < arr.size(); i++){\n int b = arr[i];\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n deque<int> dq(skills.begin(), skills.end());\n int n = skills.size();\n unordered_map<int,int>mpp;\n int max_skill = *max_element(skills.begin(), skills.end()); \n for(int i=0;i<n;i++){\...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& s, int k) {\n map <int,int> mp;\n int n=s.size();\n int maxele=0;\n\n for(int i=0;i<n;i++){\n maxele=max(maxele,s[i]);\n mp[s[i]]=i;\n }\n\n if(k>=n)\n return mp[maxele];...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n unordered_map<int,int>mp;\n int ma=INT_MIN;\n int n=skills.size();\n for(int i=0;i<skills.size();i++)\n {\n mp[skills[i]]=i;\n \n }\n queue<int>q;\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n unordered_map<int, int> mp;\n int n = skills.size();\n int maxElement = *max_element(skills.begin(), skills.end());\n deque<int> dq;\n for(int i = 0; i < skills.size(); i++){\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n unordered_map<int, int> mp;\n int n = skills.size();\n int maxElement = *max_element(skills.begin(), skills.end());\n deque<int> dq;\n for(int i = 0; i < skills.size(); i++){\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n unordered_map<int, int> mp;\n int n = skills.size();\n int maxElement = *max_element(skills.begin(), skills.end());\n deque<int> dq;\n for(int i = 0; i < skills.size(); i++){\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n int mx=-1,mxpos,n=skills.size(),x,y,val,prev=-1,i;\n deque<int> q;\n unordered_map<int,int> mp;\n\n for(i=0;i<n;i++){\n q.push_back(skills[i]);\n mp[skills[i]]=k;\n\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n unordered_map<int, int> mp;\n int n = skills.size();\n int maxElement = *max_element(skills.begin(), skills.end());\n deque<int> dq;\n for(int i = 0; i < skills.size(); i++){\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n unordered_map<int, int> mp;\n int n = skills.size();\n int maxElement = *max_element(skills.begin(), skills.end());\n deque<int> dq;\n for(int i = 0; i < skills.size(); i++){\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n unordered_map<int, int> toIdx; // skill to idx\n int n = skills.size();\n int first = skills[0];\n deque<int> ring;\n for (int i = 0; i < n; i++) {\n toIdx[skills[i]] = i;\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n unordered_map<int,int>mp;\n int n=skills.size();\n deque<int>dq;\n for(int i=0;i<n;i++){\n mp[i]=skills[i];\n dq.push_back(i);\n }\n cout<<n<<endl;\n if(k>=n-1){...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n deque<int> dq(skills.begin(), skills.end());\n int n = skills.size();\n unordered_map<int,int>mpp;\n for(int i=0;i<n;i++){\n mpp[skills[i]] = i;\n }\n int cnt = 0; // T...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n deque<int> dq(skills.begin(), skills.end());\n int n = skills.size();\n unordered_map<int,int>mpp;\n for(int i=0;i<n;i++){\n mpp[skills[i]] = i;\n }\n int cnt = 0; // T...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n = skills.size();\n deque<int>q;\n unordered_map<int,int>count; // for win count\n int highest=INT_MIN;\n int index;\n for (int i=0; i<n; i++)\n {\n q.push_back(i);\n count[i]=0;\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n = skills.size();\n vector<int> arr(n, 0);\n int x = 0, y = 0; \n unordered_map<int, int> mp;\n for(int i = 0; i < n; i++) {\n mp[skills[i]] = i;\n }\n int m...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n // void rotate(vector<int>&arr , int n)\n // {\n // int temp[n];\n\n // int k = 0;\n // for (int i = 1; i < n; i++) {\n // temp[k] = arr[i];\n // k++;\n // }\n\n // for (int i = 0; i < 1; i++) {\n // temp[...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k)\n {\n deque<int> q;\n map<int , int> mp;\n int n = skills.size();\n for(int i = 0;i<n;i++) q.push_back(i);\n \n for(int i = 0;i<3*n;i++)\n {\n int a = q.front(); q...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n\n int mx=-1,mxpos,n=skills.size(),x,y,val,prev=-1,i;\n deque<int> q;\n map<int,int> mp;\n\n for(i=0;i<n;i++){\n q.push_back(skills[i]);\n mp[skills[i]]=k;\n\n if...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n = skills.size();\n vector<int> arr(n, 0);\n int x = 0, y = 0; \n unordered_map<int, int> mp;\n for(int i = 0; i < n; i++) {\n mp[skills[i]] = i;\n }\n int m...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n unordered_map<int, pair<int, int>> mp;\n int mx = 0;\n int n = skills.size();\n for(int i = 0; i < n; i++){\n mp[skills[i]] = {i, 0};\n mx = max(mx, skills[i]);\n }\...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "// same ques as 1535. Find the Winner of an Array Game (got to know after contest)...\n\nclass Solution {\npublic:\n int findWinningPlayer(vector<int>& a, int k) {\n int ans=0;\n queue<int> q;\n map<int,int> m;\n for(int i=0;i<a.size();i++)\n q.push(a[i]);\n ...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n deque<int> dq;\n unordered_map<int, int> map;\n int i = 0;\n for(auto skill : skills) {\n dq.push_back(skill);\n map[skill] = i;\n i++;\n }\n int w...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n map < int, int > m;\n for (int i = 0; i < skills.size(); i++) {\n m[skills[i]] = i;\n }\n int n= skills.size();\n deque<int> de;\n for (int i = 0; i < skills.size(); i++...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n deque<pair<int,int>> dq;\n int n = skills.size();\n for(int i = 0 ; i < n; i++)\n dq.push_back({skills[i], i});\n unordered_map<int,int> mp;\n while(true){\n pair<in...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n = skills.size();\n unordered_map<int,int> mpp;\n int maxi = INT_MIN;\n int maxIndex = -1;\n for(int i=0;i<n;i++){\n mpp[i] = skills[i];\n if(skills[i] > maxi){...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& a, int k) {\n int n= a.size();\n unordered_map<int,int> playerwins,mapping;\n \n for(int i=0;i<n;i++)\n mapping[a[i]]= i;\n \n int check=0;\n deque<int> q;\n \n for(in...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& a, int k) {\n int n= a.size();\n deque<int> q;\n unordered_map<int,int> playerwins,mapping;\n \n for(int i=0;i<n;i++)\n mapping[a[i]]= i;\n \n for(int i=0;i<n;i++)\n q.pu...
3,413
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p> <p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All ...
3
{ "code": "class Solution {\npublic:\n int findWinningPlayer(vector<int>& skills, int k) {\n int n=skills.size();\n int mx=0;\n\n map<int,int>idx;\n for(int i=0;i<n;i++){\n if(mx<skills[i]){\n mx=skills[i];\n \n }\n idx[skills[...
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...
0
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n \n int n = nums.size();\n int dp[n][k+1];\n int ans = 0;\n for(int i = 0;i<n;i++){\n for(int j = 0;j<=k;j++){\n int maxi = 0;\n for(int l = 0;l<i;l++){\...
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...
0
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& a, int k) {\n int i,j,n=a.size(),t;\n int dp[n][k+1],ans=0;\n memset(dp,0,sizeof(dp));\n dp[0][0]=1;\n for(i=1;i<n;i++){\n dp[i][0]=1;\n for(j=0;j<i;j++){\n for(t=0;t<=k;t++...
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...
1
{ "code": "template<class Info, class Tag>\nstruct LazySegmentTree {\n const int n;\n std::vector<Info> info;\n std::vector<Tag> tag;\n LazySegmentTree(int n) : n(n), info(4 << std::__lg(n)), tag(4 << std::__lg(n)) {}\n LazySegmentTree(std::vector<Info> init) : LazySegmentTree(init.size()) {\n s...
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...
1
{ "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,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...
1
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n int som=1;\n vector<int>res;\n for(int i=0;i<(nums.size()-1);i++){\n if(nums[i]==nums[i+1]){\n som++;\n }\n else{\n res.push_back(som);\n ...
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...
1
{ "code": "class Solution {\npublic:\n int maximumLength(vector<int>& nums, int k) {\n dp = vector<vector<int>>(503,vector<int>(k+1,0));\n // [x,x,x,j,x,x],x,x,i\n int n = nums.size();\n int ret = 0;\n\n for(int i = 0; i < n; i++){\n for(int t = 0; t <= k; t++){\n ...
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...
1
{ "code": "//Q: A sequence of integers seq is called good if there are ATMOST k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible LENGTH of a good subsequence of nums[].\n#define ll long long\nint dp[501][501][26];\n//1 <= nums.length <= 500, 0 <= k <= min(nums.len...
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...
1
{ "code": "//Q: A sequence of integers seq is called good if there are ATMOST k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1]. Return the maximum possible LENGTH of a good subsequence of nums[].\n#define ll long long\nint dp[501][501][26];\n//1 <= nums.length <= 500, 0 <= k <= min(nums.len...
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...
2
{ "code": "class Solution {\npublic:\n int dp[502][502][27];\n\n int helper(int index, int lst, int k, vector<int> &nums){\n if(index > nums.size())\n return 0;\n if(dp[index][lst][k] != -1)\n return dp[index][lst][k];\n dp[index][lst][k] = helper(index + 1, lst, k, nu...
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...
2
{ "code": "class Solution {\npublic:\n int dp[502][502][27];\n int fun(vector<int> &v, int x ,int k, int last, int n) {\n // cout << x << \" \" << k << endl;\n if(n <= x) {\n return 0;\n }\n if(dp[x][last][k] != -1) {\n return dp[x][last][k];\n }\n ...
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...
2
{ "code": "class Solution {\npublic:\n int dp[600][600][30];\nint f(int index,int prevIndex,int k,vector<int> &nums){\n if(index==nums.size()) return 0;\n\n if(dp[index][prevIndex+1][k]!=-1) return dp[index][prevIndex+1][k];\n int pick = 0;\n // pick\n if(prevIndex==-1 || nums[pr...
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...
2
{ "code": "class Solution {\npublic:\n int dp[600][600][30];\nint f(int index,int prevIndex,int k,vector<int> &nums){\n if(index==nums.size()) return 0;\n\n if(dp[index][prevIndex+1][k]!=-1) return dp[index][prevIndex+1][k];\n int pick = 0;\n // pick\n if(prevIndex==-1 || nums[pr...
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...
2
{ "code": "class Solution {\npublic:\n int dp[600][600][30];\nint f(int index,int prevIndex,int k,vector<int> &nums){\n if(index==nums.size()) return 0;\n\n if(dp[index][prevIndex+1][k]!=-1) return dp[index][prevIndex+1][k];\n int pick = 0;\n // pick\n if(prevIndex==-1 || nums[pr...
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...
2
{ "code": "\n\n\n\nclass Solution {\n // int dp[505][26];\npublic:\n int maximumLength(vector<int>& nums, int k) {\n vector<vector<int>> dp(505, vector<int>(26, 0));\n int N = nums.size();\n int rst = 1;\n for (int i=0; i<N; i++){\n for (int t=0; t<=k; t++){\n ...
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...
2
{ "code": "\n// https://github.com/wisdompeak/LeetCode/tree/master/Dynamic_Programming/3177.Find-the-Maximum-Length-of-a-Good-Subsequence-II\n// 对于常规的DP解法,我们容易设置状态变量dp[i][t]表示前i个元素里、\n// 我们已经出现了t次相邻元素不等的情况下,能够得到的goode subsequence的最大长度。\n// 显然转移的突破口就在于nums[i]是否与sequence的前一个元素相同。\n// 我们枚举j<i作为序列里i之前的一个元素,只要nums[j]==num...
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...
2
{ "code": "using int64 = long long;\n\nclass segtree {\npublic:\n struct node {\n // don't forget to set default value (used for leaves)\n // not necessarily neutral element!\n int64 tag = 0, mx = 0;\n\n void apply(int l, int r, int64 v) {\n tag = v;\n mx = (r - l ...
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...
2
{ "code": "using int64 = long long;\n\nclass segtree {\npublic:\n struct node {\n // don't forget to set default value (used for leaves)\n // not necessarily neutral element!\n int64 tag = 0, mx = 0;\n\n void apply(int l, int r, int64 v) {\n tag = v;\n mx = (r - l ...
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...
2
{ "code": "class Solution {\npublic:\n int dp[600][600][50];\n int f(int i,int p,int cnt,int k,vector<int>& nums){\n if(i==nums.size()) return 0;\n if(dp[i][p+1][cnt]!=-1) return dp[i][p+1][cnt];\n int ans=0;\n if(p==-1){\n ans=max(ans,1+f(i+1,i,cnt,k,nums));\n ...
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...
2
{ "code": "class Solution {\npublic:\n int dp[600][600][50];\n int f(int i,int p,int cnt,int k,vector<int>& nums){\n if(i==nums.size()) return 0;\n if(dp[i][p+1][cnt]!=-1) return dp[i][p+1][cnt];\n int ans=0;\n if(p==-1){\n ans=max(ans,1+f(i+1,i,cnt,k,nums));\n ...
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...
2
{ "code": "class Solution {\npublic:\n int dp[600][600][50];\n int f(int i, int p, int cnt, int k, vector<int>& nums) {\n if (i == nums.size())\n return 0;\n if (dp[i][p + 1][cnt] != -1)\n return dp[i][p + 1][cnt];\n int ans = 0;\n if (p == -1) {\n an...
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...
2
{ "code": "#include <bits/stdc++.h>\n#pragma GCC optimize(2)\n#define rep(i, a, b) for (int i = (a); i < (b); ++i)\n#define rep_(i, a, b) for (int i = (a); i > (b); i--)\n#define mst(x, a) memset(x, a, sizeof(x))\n#define all(a) begin(a), end(a)\n#define lowbit(x) ((x) & (-(x)))\n#define bitcnt(x) (__builtin_popcount...
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...
2
{ "code": "class Solution {\npublic:\n int rec(int i,bool same,int k,vector<int>&nums,unordered_map<int,vector<int>>&mp,vector<vector<vector<int>>>&dp)\n {\n if(i>=nums.size() || k<0) return 0;\n if(dp[i][same][k]!=-1) return dp[i][same][k];\n vector<int>temp=mp[nums[i]];\n int next_ind=uppe...
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...
2
{ "code": "class Solution {\npublic:\n int K;\n int solve(vector<int> & nums, int index, int prev, int k ,vector<int>& dp){\n if(index>=nums.size()) return 0;\n\n // if(dp[index][prev+1][k]!=-1) return dp[index][prev+1][k];\n if(dp[(index*(nums.size()+1)*(K+1))+((prev+1)*(K+1))+k]!=-1)...
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...
2
{ "code": "class Solution {\npublic:\n int yesRec(int i, int curr, int prev, vector<int> &nums, int k, vector<vector<vector<int>>> &dp)\n {\n if (i == nums.size())\n return 0;\n\n if (dp[i][curr][prev + 1] != -1)\n return dp[i][curr][prev + 1];\n\n int notTake = yesRec...
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...
2
{ "code": "class Solution {\n\nprivate:\n\n int f(int ind , int last , int k , vector<int> &nums , vector<vector<vector<int>>> &dp){\n\n if(ind == nums.size()){\n return dp[ind][k][last+1] = 0;\n }\n\n if(dp[ind][k][last+1] != -1) return dp[ind][k][last+1];\n\n int np = f(ind...
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...
2
{ "code": "class Solution {\npublic:\n\n int getMax(vector<int>nums, int k, int idx, vector<vector<int>>&memo){\n\n if(idx == nums.size()-1){\n memo[idx][k] = 1;\n return 1;\n }\n\n int element = nums[idx];\n int max_ans = 1;\n for(int i = idx+1; i <nums.siz...
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...
2
{ "code": "class Solution\n{\npublic:\n int yesRec(int i, int curr, int prev, vector<int> &nums, int k, vector<vector<vector<int>>> &dp)\n {\n if (i == nums.size())\n return 0;\n\n if (dp[i][curr][prev + 1] != -1)\n return dp[i][curr][prev + 1];\n\n int notTake = yesRe...
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...
2
{ "code": "class Solution {\npublic:\n int solve(int ind,vector<int>& nums, int k,int last,vector<vector<vector<int>>> &dp){\n int n=nums.size();\n if(ind>=n) return 0;\n int take=0;\n int notTake=0;\n if(last!=-1 && dp[ind][k][last]!=-1) return dp[ind][k][last];\n notTake...
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...
2
{ "code": "class Solution {\npublic:\n int dp(int i, int cnt, int k, int prevIndex, vector<vector<vector<int>>> &arr, vector<int> &nums)\n {\n if(cnt > k) return -1;\n \n if(prevIndex != -1 && arr[i][cnt][prevIndex] != -1) return arr[i][cnt][prevIndex];\n \n if(prevIndex != -1...
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...
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,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 helper(int index,int k,int last,vector<int>& nums,vector<vector<vector<int>>>& dp){\n if(index==nums.size()){\n return 0;\n }\n if(dp[index][k][last]!=-1){\n return dp[index][k][last];\n }\n int x=helper(index+1,k,l...
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\n{\npublic:\n int yesRec(int i, int curr, int prev, vector<int> &nums, int k, vector<vector<vector<int>>> &dp)\n {\n if (i == nums.size())\n return 0;\n\n if (dp[i][curr][prev + 1] != -1)\n return dp[i][curr][prev + 1];\n\n int notTake = yesRe...
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 {\nprivate:\n int find(int ind,const vector<int>&nums,int k,int prev_ind,vector<vector<vector<int>>>&dp) {\n if (ind >= nums.size())return 0;\n if (~dp[ind][k][prev_ind + 1])return dp[ind][k][prev_ind + 1];\n int notTake=find(ind+1,nums,k,prev_ind,dp);\n int ta...
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\n{\npublic:\n int yesRec(int i, int curr, int prev, vector<int> &nums, int k, vector<vector<vector<int>>> &dp)\n {\n if (i == nums.size())\n return 0;\n\n if (dp[i][curr][prev + 1] != -1)\n return dp[i][curr][prev + 1];\n\n int take = 0;\n ...
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\n int n;\n vector <int> arr;\n\n int f(int ind,int k,int prev,vector <vector <vector <int>>> &dp){\n\n if(ind==n)\n return 0;\n if(dp[ind][k][prev+1]!=-1)\n return dp[ind][k][prev+1];\n\n if(prev == -1){\n return dp[ind][k][p...
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 solve(vector<int>& a, int k, int index, int pre,\n vector<vector<vector<int>>>& dp) {\n if (index >= a.size())\n return 0;\n if (dp[index][k][pre + 1] != -1)\n return dp[index][k][pre + 1];\n int ans1 = 0;\n i...
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 vector<int> nums;\n unordered_map<int,int> mp;\n vector<vector<vector<int>>> M;\n int dp(int left, int rem, int last){\n int pl = last;\n last = mp[last];\n if(rem < 0)\n return 0;\n if(left == nums.size())\n return 0...
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 vector<int> A;\n unordered_map<int,int> mp;\n vector<vector<vector<int>>> M;\n int inc = 0, n;\n int D(int i, int r, int l){\n if(i == n)\n return 0;\n if(M[i][r][l] == -1){\n if(l == 0)\n M[i][r][l] = max(D(i+1,r...
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 f(int ind,int k,int prev,vector<int>&nums,vector<vector<vector<int>>>&dp){\n\n if(k<0) return-1e7;\n if(ind == nums.size())return 0;\n if(dp[ind][k+1][prev+1]!=-1)return dp[ind][k+1][prev+1];\n\n int total = 0;\n if(prev!=-1 && nums[prev...
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\n int solve(vector<int>& nums, int k, int i, int prev, vector <vector <vector <int>>> &dp) {\n\n if(i == nums.size()) return 0;\n\n if(dp[i][k][prev] != -1) return dp[i][k][prev];\n\n int pick = 0, leave = 0;\n\n if(prev == nums.size() or nums[i] !...
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 solve(vector<int>&nums,int k,int prev,int curr,vector<vector<vector<int>>>&dp){\n\n if(curr>=nums.size()){\n\n return 0;\n }\n if(dp[k][prev+1][curr]!=-1){\n\n return dp[k][prev+1][curr];\n }\n int include=0;\n\n ...
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 long long f(int i,vector<int>& nums, int k,int prev,vector<vector<vector<long long>>>&dp){\nif(i>=nums.size())return 0;\n\n if(dp[i][k][prev+1]!=-1)return dp[i][k][prev+1];\n long long take = INT_MIN;\n long long notake = f(i+1,nums,k,prev,dp);\n if(k==0 || prev==-1){\...
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 vector<vector<vector<int>>>dp;\n int dfs(int i, int prev, int k, vector<int>&nums, int n){\n if(i == nums.size()) return 0;\n if(dp[i][prev + 1][k] != -1) return dp[i][prev + 1][k];\n\n int ans = 0;\n if(prev == -1){\n ans = max(ans, ...
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\n int cnt(int ctr,int prev,vector<vector<vector<int>>>&dp,vector<int>& nums,int k)\n {\n if(ctr>=nums.size())\n return 0;\n\n \n if(dp[ctr][prev+1][k]!=-1)\n return dp[ctr][prev+1][k];\n\n /* if(ctr==nums.size()-1)\n {\...
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\n int cnt(int ctr,int prev,vector<vector<vector<int>>>&dp,vector<int>& nums,int k)\n {\n if(ctr>=nums.size())\n return 0;\n\n \n if(dp[ctr][prev+1][k]!=-1)\n return dp[ctr][prev+1][k];\n\n /* if(ctr==nums.size()-1)\n {...
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 solver(vector<int>& nums, int m, int j,int i, int n, int k,vector<vector<vector<int>>>&dp )\n {\n if(m>k)\n return -1;\n\n if(i>=n)\n return 0;\n\n if(dp[i][j][m]!=-1)\n return dp[i][j][m];\n\n int ans = 0;\n an...
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 finder(int curr, int prev, int count, vector<int>& nums, vector<vector<vector<int>>>& dp) {\n if (curr == nums.size())\n return 0;\n int ans = -1;\n\n if (dp[curr][prev + 1][count] != -1)\n return dp[curr][prev + 1][count];\n ...
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 vector<vector<vector<int>>> memo(\n n + 1, vector<vector<int>>(n + 1, vector<int>(26, -1)));\n return find(0, -1, k, nums, memo);\n }\n //memoization 3D DP include - e...
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 {\n vector<vector<vector<int>>> dp;\n\n int func(vector<int> &nums,int k,int ind,int prev_ind,int c)\n {\n int n=nums.size();\n\n if(c>k)\n return INT_MIN;\n\n if(ind<0)\n {\n return 0;\n }\n\n if(dp[ind][prev_ind][c]!=-1)\...
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 solve(int idx, int lastIdx, int k, vector<int>& nums, vector<vector<vector<int>>>& dp) {\n if(idx == nums.size()) return 0;\n\n if(dp[idx][lastIdx + 1][k] != -1)\n return dp[idx][lastIdx + 1][k];\n \n int res = solve(idx + 1, lastIdx...
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 f(int prev,int i,int curr,int k,vector<int>&nums,int n,vector<vector<vector<int>>>&dp){\n if(i == n){\n return 0;\n }\n\n if(dp[i][prev+1][curr] != -1)return dp[i][prev+1][curr];\n \n int nottake=f(prev,i+1,curr,k,nums,n,dp);\...
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": "#define dc false\n#define print(arr) if(dc){for(int i=0;i<arr.size();i++){cout<<arr[i]<<\" \";}cout<<endl;}\n#define deb(x) if(dc) cout<<\" --> \"<<(#x)<<\" : \"<<x<<endl;\n#define deb2(x, y) if(dc) cout<<\" --> \"<<(#x)<<\" : \"<<x<<\" , \"<<(#y)<<\" : \"<<y<<endl;\n#define debs(x) if(dc) cout<<\"--> \"<<...
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 func(vector<int>& nums, int curr, int prev, int k, vector<vector<vector<int>>>& dp){\n if(curr<0) return 0;\n if(dp[curr][prev][k]!=-1) return dp[curr][prev][k];\n if(nums[curr]!=nums[prev]){\n if(k==0) return dp[curr][prev][k] = func(nums,...
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 solve(vector<int> &nums, int prev, int i, int k, vector<vector<vector<int>>> &dp) {\n int n = nums.size();\n if(i == n)\n return 0;\n \n if(dp[prev+1][i][k] != -1)\n return dp[prev+1][i][k];\n \n int choose =...
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 {\n vector<vector<vector<int>>>dp;\n int n;\npublic:\n int maximumLength(vector<int>& nums, int k) {\n n = nums.size();\n if(!n)\n return 0;\n int ret = 0;\n dp = vector<vector<vector<int>>>(n+1, vector<vector<int>>(n, vector<int>(k+1, INT_MIN)...
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 {\n\nprivate:\n \n int findMinLen(vector<int>& nums, int k, int i, int prevIdx, \n int usedK, vector<vector<vector<int>>>& dp) {\n \n if (i >= nums.size()) {\n return 0;\n }\n \n if (dp[i][prevIdx+1][usedK] != -1) {\n ...
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 {\n int f(int ind,int prev,int count,vector<vector<vector<int>>>&dp,vector<int>&arr,int k){\n if(count>k)return -1e9;\n if(ind == arr.size()){\n return 0;\n }\n\n if(dp[ind][prev+1][count]!=-1)return dp[ind][prev+1][count];\n\n int nottake = f...
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\n int func(int ind, int prev, int k, vector<int> &nums,vector<vector<vector<int>>> &dp){\n if(ind == nums.size()) return 0;\n\n int take = 0, nt = 0;\n if(dp[ind][prev+1][k]!=-1) return dp[ind][prev+1][k];\n\n nt = func(ind+1, prev, k,nums,dp);...
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 vector<vector<vector<int>>> dp;\n int solve(int i, int j, int k,vector<int>& nums){\n // cout<<i<<' '<<j<<' '<<k<<endl;\n if(i==nums.size())\n return 0;\n if(dp[i][j][k]!=-1) return dp[i][j][k];\n int ans=solve(i+1,j,k,nums);\n if(...
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 vector<int> arr;\n int K;\n vector<vector<vector<int>>> memo;\n\n int solve(int i, int prevIndex, int count) {\n \n if (i >= arr.size()) {\n return (count <= K) ? 0 : INT_MIN;\n }\n if (memo[i][prevIndex][count] != -1) {\n ...
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 // Below is a Memoized code of TC - close to 1e7 -- TLE\n /*\n int solve(int ind , int prev , int k , int n , vector<vector<vector<int>>> &dp , vector<int> &nums){\n if(k < 0) return -1e6;\n if(ind >= n) return 0;\n\n if(dp[ind][prev + 1][k] != -1) ...