ru
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

Открыть в Telegram

Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards Channel link : https://t.me/leetcode_gfg_potd

Больше
1 250
Подписчики
+224 часа
+147 дней
+2930 день
Архив постов
GFG | Problem of the day :

class Solution { public: bool makeEqual(vector& words) { int n = words.size(); unordered_map mp; for(int i=0; i

LeetCode | Daily challenge :

class Solution{ public: //Function to return the name of candidate that received maximum votes. vector winner(string arr[], int n) { map mp; int maxi = 0; string str; for(int i = 0; i < n; i++) mp[arr[i]]++; for(auto i: mp) { if(i.second > maxi) { maxi = i.second; str = i.first; } } return {str, to_string(maxi)}; } };

GFG | Problem of the day :

class Solution { public: int minDifficulty(vector& jobDifficulty, int d) { if(jobDifficulty.size()> dp(n+1,vector(d+1,INT_MAX/2)); dp[0][0]=0; for(int i=1;i<=n;i++){ for(int k=1;k<=d;k++){ int temp=0; for(int j=i-1;j>=k-1;j--){ temp=max(temp,jobDifficulty[j]); dp[i][k]=min(dp[i][k],dp[j][k-1]+temp); } } } return dp[n][d]; } };

LeetCode | Daily challenge :

class Solution{ public: int kSubstrConcat (int n, string s, int k) { if(n%k!=0) { return 0; } string ans; int val =0; unordered_map count; for(int i=0; i< n; i+=k) { if(!count.count(s.substr(i,k))) { val++; } count[s.substr(i,k)] = true; } if(val >2) { return 0; } return 1; } };

GFG | Problem of the day :

int dp[101][27][101][101]; class Solution { public: string str; int n; int minLength(int i, int prev, int len, int k) { if(k<0) return INT_MAX; if(i>=n) return 0; if(dp[i][prev][len][k] != -1) return dp[i][prev][len][k]; int ifDelete = minLength(i+1,prev,len,k-1); int keep = 0; if(str[i]-'a' == prev) { if(len==1 or len==9 or len==99) keep++; keep += minLength(i+1, prev, len+1, k); } else keep = 1 + minLength(i+1, str[i]-'a', 1, k); return dp[i][prev][len][k] = min(ifDelete, keep); } int getLengthOfOptimalCompression(string s, int k) { str = s; n = s.size(); memset(dp,-1,sizeof(dp)); return minLength(0,26,0,k); } };

LeetCode | Daily challenge :

class Solution{ public: bool match(string wild, string pattern){ int n = wild.length(); int m = pattern.length(); int i = 0, j = 0; for (;j

GFG | Problem of the day :

class Solution { public: int minCost(string colors, vector& neededTime) { int ans=0; int prev=neededTime[0]; bool fl=false; for(int i=1;i

LeetCode | Daily challenge :

class Solution { public: vector antiDiagonalPattern(vector> v) { int n = v.size(); if (n == 0 ) {}; vector ans; vector> visited(n, vector (n, 0)); queue< pair < int, int >> q; q.push({0,0}); while(!q.empty()) { int size = q.size(); while(size--) { pair qf = q.front(); q.pop(); int x = qf.first; int y = qf.second; ans.push_back(v[x][y]); if ( y + 1 < n && !visited[x][y+1]) { q.push({x, y+1}); visited[x][y+1] = true; } if( x + 1 < n && !visited[x+1][y] ) { q.push({x+1, y}); visited[x+1][y] = true; } } } return ans; } };

GFG | Problem of the day :

class Solution { public: vector> dp; int mod = 1e9 + 7; int util(int dice_left, int sum_left, int k) { if(dice_left < 0) return 0; if(sum_left == 0) return dice_left == 0; if(dp[dice_left][sum_left] != -1) return dp[dice_left][sum_left]; int ret = 0; for(int l = 1; l <= k; l++) { if(sum_left >= l) { ret = (ret + util(dice_left-1,sum_left-l,k)) % mod; } } return dp[dice_left][sum_left] = ret; } int numRollsToTarget(int n, int k, int target) { dp.resize(n+1 , vector (target+1, -1)); return util(n,target,k); } };

LeetCode | Daily challenge :

class Solution{ public: vector> sumZeroMatrix(vector> a){ int m = a.size(); int n = a[0].size(); int left, right, up, down; left = right = up = down = 0; for(int i=0; i arr(m, 0); for(int j=i; j map; map[0] = -1; int l=0, r=0; long long sum = 0; for(int k=0; k (r-l)){ l = map[sum]+1; r = k+1; } } else{ map[sum] = k; } } if((j-i+1)*(r-l) > (right-left)*(down-up)){ up = l; down = r; left = i; right = j+1; } } } vector> result; for(int i=up; i arr; for(int j=left; j